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;
/**
*/
public $className = BoxEditor::class;
+ /**
+ * box contents
+ * @var array
+ */
+ protected $content = [];
+
/**
* @inheritDoc
*/
* @throws SystemException
*/
protected function prepareImport(array $data) {
+ $content = [];
$boxType = $data['elements']['boxType'];
$controller = '';
$identifier = $data['attributes']['identifier'];
}
}
+ $content = $data['elements']['content'];
+
break;
default:
return [
'identifier' => $identifier,
+ 'content' => $content,
'name' => $this->getI18nValues($data['elements']['name'], true),
'boxType' => $boxType,
'position' => $position,
* @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
// 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 (?, ?, ?)";