From 2e9f64a7f7e32ed89cb3aac7eb192f3fad9e26a3 Mon Sep 17 00:00:00 2001 From: joyqi Date: Thu, 14 Dec 2017 11:27:42 +0800 Subject: [PATCH] fix #689 --- var/Widget/Backup.php | 45 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/var/Widget/Backup.php b/var/Widget/Backup.php index bc0fd77a..acc6e51e 100644 --- a/var/Widget/Backup.php +++ b/var/Widget/Backup.php @@ -28,6 +28,27 @@ class Widget_Backup extends Widget_Abstract_Options implements Widget_Interface_ 'fields' => 6 ); + private $_fields = array( + 'contents' => array( + 'cid', 'title', 'slug', 'created', 'modified', 'text', 'order', 'authorId', + 'template', 'type', 'status', 'password', 'commentsNum', 'allowComment', 'allowPing', 'allowFeed', 'parent' + ), + 'comments' => array( + 'coid', 'cid', 'created', 'author', 'authorId', 'ownerId', + 'mail', 'url', 'ip', 'agent', 'text', 'type', 'status', 'parent' + ), + 'metas' => array( + 'mid', 'name', 'slug', 'type', 'description', 'count', 'order', 'parent' + ), + 'relationships' => array('cid', 'mid'), + 'users' => array( + 'uid', 'name', 'password', 'mail', 'url', 'screenName', 'created', 'activated', 'logged', 'group', 'authCode' + ), + 'fields' => array( + 'cid', 'name', 'type', 'str_value', 'int_value', 'float_value' + ) + ); + /** * @var array */ @@ -38,6 +59,26 @@ class Widget_Backup extends Widget_Abstract_Options implements Widget_Interface_ */ private $_login = false; + /** + * 过滤字段 + * + * @param $table + * @param $data + * @return array + */ + private function applyFields($table, $data) + { + $result = array(); + + foreach ($data as $key => $val) { + if (in_array($key, $this->_fields[$table])) { + $result[$key] = $val; + } + } + + return $result; + } + /** * @param $type * @param $data @@ -165,7 +206,7 @@ class Widget_Backup extends Widget_Abstract_Options implements Widget_Interface_ $this->reLogin($data); } - $db->query($db->insert('table.' . $table)->rows($data)); + $db->query($db->insert('table.' . $table)->rows($this->applyFields($table, $data))); } catch (Exception $e) { $this->widget('Widget_Notice')->set(_t('恢复过程中遇到如下错误: %s', $e->getMessage()), 'error'); $this->response->goBack(); @@ -213,7 +254,7 @@ class Widget_Backup extends Widget_Abstract_Options implements Widget_Interface_ $page ++; foreach ($rows as $row) { - $buffer .= $this->buildBuffer($val, $row); + $buffer .= $this->buildBuffer($val, $this->applyFields($type, $row)); if (sizeof($buffer) >= 1024 * 1024) { echo $buffer;