fix attachment handle (#1696)

* fix #1694

* fix array dump

* add toColumn method
This commit is contained in:
joyqi 2024-01-09 14:31:15 +08:00 committed by GitHub
parent db5d8694c4
commit 7115a30301
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 20 deletions

View File

@ -303,6 +303,24 @@ abstract class Widget
}
}
/**
* @param string|array $column
* @return array|mixed|null
*/
public function toColumn($column)
{
if (is_array($column)) {
$item = [];
foreach ($column as $key) {
$item[$key] = $this->{$key};
}
return $item;
} else {
return $this->{$column};
}
}
/**
* @param string|array $column
* @return array
@ -312,16 +330,7 @@ abstract class Widget
$result = [];
while ($this->next()) {
if (is_array($column)) {
$item = [];
foreach ($column as $key) {
$item[$key] = $this->{$key};
}
$result[] = $item;
} else {
$result[] = $this->{$column};
}
$result[] = $this->toColumn($column);
}
return $result;

View File

@ -313,7 +313,7 @@ class Edit extends Contents implements ActionInterface
if ($this->isWriteable(clone $condition) && $this->delete($condition)) {
/** 删除文件 */
Upload::deleteHandle($row);
Upload::deleteHandle($this->toColumn(['cid', 'attachment', 'parent']));
/** 删除评论 */
$this->db->query($this->db->delete('table.comments')

View File

@ -114,7 +114,8 @@ class Upload extends Contents implements ActionInterface
'table.contents.cid = ?',
$this->request->filter('int')->get('cid')
)
->where('table.contents.type = ?', 'attachment'), [$this, 'push']
->where('table.contents.type = ?', 'attachment'),
[$this, 'push']
);
if (!$this->have()) {
@ -132,7 +133,7 @@ class Upload extends Contents implements ActionInterface
$file['name'] = urldecode($file['name']);
}
$result = self::modifyHandle($this->row, $file);
$result = self::modifyHandle($this->toColumn(['cid', 'attachment', 'parent']), $file);
if (false !== $result) {
self::pluginHandle()->call('beforeModify', $result);
@ -341,7 +342,6 @@ class Upload extends Contents implements ActionInterface
'url' => $this->attachment->url,
'permalink' => $this->permalink
]]);
}
}
}

View File

@ -14,6 +14,7 @@ use Typecho\Widget;
use Typecho\Widget\Exception as WidgetException;
use Widget\Base\Comments;
use Widget\Base\Contents;
use Widget\Contents\Attachment\Unattached;
use Widget\Contents\Page\Admin as PageAdmin;
use Widget\Contents\Post\Admin as PostAdmin;
use Widget\Contents\Attachment\Admin as AttachmentAdmin;
@ -406,17 +407,16 @@ class XmlRpc extends Contents implements ActionInterface, Hook
}
/** 对未归档附件进行归档 */
$unattached = $this->db->fetchAll($this->select()->where('table.contents.type = ? AND
(table.contents.parent = 0 OR table.contents.parent IS NULL)', 'attachment'), [$this, 'filter']);
$unattached = Unattached::alloc();
if (!empty($unattached)) {
foreach ($unattached as $attach) {
if (false !== strpos($input['text'], $attach['attachment']->url)) {
if ($unattached->have()) {
while ($unattached->next()) {
if (false !== strpos($input['text'], $unattached->attachment->url)) {
if (!isset($input['attachment'])) {
$input['attachment'] = [];
}
$input['attachment'][] = $attach['cid'];
$input['attachment'][] = $unattached->cid;
}
}
}