From: Matthias Schmidt Date: Sat, 30 Apr 2016 17:05:14 +0000 (+0200) Subject: Add support for static boxes in PIP X-Git-Tag: 3.0.0_Beta_1~1789 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=6406bdd72cd34acd0c4b4f011dbe6e13f7e59a29;p=GitHub%2FWoltLab%2FWCF.git Add support for static boxes in PIP --- diff --git a/wcfsetup/install/files/lib/system/package/plugin/BoxPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/BoxPackageInstallationPlugin.class.php index 33672ddc69..fd01f9faa6 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/BoxPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/BoxPackageInstallationPlugin.class.php @@ -4,6 +4,7 @@ use wcf\data\box\Box; use wcf\data\box\BoxEditor; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\exception\SystemException; +use wcf\system\language\LanguageFactory; use wcf\system\WCF; /** @@ -22,6 +23,12 @@ class BoxPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin */ public $className = BoxEditor::class; + /** + * box contents + * @var array + */ + protected $content = []; + /** * @inheritDoc */ @@ -108,6 +115,7 @@ class BoxPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin * @throws SystemException */ protected function prepareImport(array $data) { + $content = []; $boxType = $data['elements']['boxType']; $controller = ''; $identifier = $data['attributes']['identifier']; @@ -147,6 +155,8 @@ class BoxPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin } } + $content = $data['elements']['content']; + break; default: @@ -160,6 +170,7 @@ class BoxPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin return [ 'identifier' => $identifier, + 'content' => $content, 'name' => $this->getI18nValues($data['elements']['name'], true), 'boxType' => $boxType, 'position' => $position, @@ -215,19 +226,57 @@ class BoxPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin * @inheritDoc */ protected function import(array $row, array $data) { + // extract content + $content = $data['content']; + unset($data['content']); + // updating boxes is only supported for 'system' type boxes, all other // types would potentially overwrite changes made by the user if updated if (!empty($row) && $row['boxType'] !== 'system') { - return new Box(null, $row); + $box = new Box(null, $row); + } + else { + $box = parent::import($row, $data); } - return parent::import($row, $data); + // store content for later import + $this->content[$box->boxID] = $content; + + return $box; } /** * @inheritDoc */ protected function postImport() { + if (!empty($this->content)) { + $sql = "INSERT IGNORE INTO wcf".WCF_N."_box_content + (boxID, languageID, title, content) + VALUES (?, ?, ?, ?)"; + $statement = WCF::getDB()->prepareStatement($sql); + + WCF::getDB()->beginTransaction(); + foreach ($this->content as $boxID => $contentData) { + foreach ($contentData as $languageCode => $content) { + $languageID = null; + if ($languageCode != '') { + $language = LanguageFactory::getInstance()->getLanguageByCode($languageCode); + if ($language === null) continue; + + $languageID = $language->languageID; + } + + $statement->execute([ + $boxID, + $languageID, + $content['title'], + isset($content['content']) ? $content['content'] : '' + ]); + } + } + WCF::getDB()->commitTransaction(); + } + if (empty($this->visibilityExceptions)) return; // get all boxes belonging to the identifiers @@ -248,7 +297,7 @@ class BoxPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin // save visibility exceptions $sql = "DELETE FROM wcf".WCF_N."_box_to_page WHERE boxID = ?"; - $deleteStatement = WCF::getDB()->prepareStatement($sql); + $deleteStatement = WCF::getDB()->prepareStatement($sql); $sql = "INSERT IGNORE wcf".WCF_N."_box_to_page (boxID, pageID, visible) VALUES (?, ?, ?)"; diff --git a/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php index 158d9a7cf6..49149edc6f 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php @@ -162,7 +162,7 @@ class PagePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin case 'html': case 'text': - case 'tpl': + case 'tpl': if (empty($data['elements']['content'])) { throw new SystemException("Missing required 'content' element(s) for page '{$identifier}'"); } @@ -262,6 +262,8 @@ class PagePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin // store content for later import $this->content[$object->pageID] = $content; + + return $object; } /**