checkTableExists('photos_page_blocks_relation') && $this->checkTableExists('photos_blocks_relation'); } /** Add selectable photos to each page block */ public function upgrade_PageBlockPhotos() { sqlQuery(' CREATE TABLE photos_blocks_relation ( id_photo INT UNSIGNED, `id_block` int(11) UNSIGNED DEFAULT NULL, position int null, CONSTRAINT id_photo UNIQUE (id_photo, id_block), FOREIGN KEY (id_photo) REFERENCES photos (id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (id_block) REFERENCES blocks (id) ON UPDATE CASCADE ON DELETE CASCADE )'); } public function check_RenameBlocksPhotosTable() { // run migration only if photos_page_blocks_relation exists AND photos_blocks_relation doesn't return !$this->checkTableExists('photos_page_blocks_relation') && $this->checkTableExists('photos_blocks_relation'); } /** Rename photos_page_blocks_relation to photos_blocks_relation*/ public function upgrade_RenameBlocksPhotosTable() { sqlQuery('RENAME TABLE photos_page_blocks_relation TO photos_blocks_relation;'); sqlQuery(' ALTER TABLE photos_blocks_relation DROP FOREIGN KEY photos_blocks_relation_ibfk_2, DROP KEY id_page_block, CHANGE `id_page_block` `id_block` int(11) UNSIGNED DEFAULT NULL, ADD FOREIGN KEY (id_block) REFERENCES blocks (id) ON UPDATE CASCADE ON DELETE CASCADE;'); } public function check_Name100Chars() { return $this->checkColumnType('blocks', 'name', 'VARCHAR(100)'); } /** Make block title 100 chars long */ public function upgrade_Name100Chars() { sqlQuery(' ALTER TABLE blocks CHANGE `name` `name` VARCHAR(100);'); $this->upgradeOK(); } public function check_JsonContent() { return $this->checkColumnExists('blocks', 'json_content'); } /** Add json_content into blocks */ public function upgrade_JsonContent() { sqlQuery('ALTER TABLE blocks ADD COLUMN json_content LONGTEXT NULL AFTER content'); $blocks_translations = false; if (findModule(\Modules::TRANSLATIONS) && $this->checkColumnExists('blocks_translations', 'json_content')) { sqlQuery('ALTER TABLE blocks_translations ADD COLUMN json_content LONGTEXT NULL AFTER content'); $blocks_translations = true; } foreach (sqlQuery('SELECT id, content FROM blocks') as $block) { $id_block = $block['id']; $uuid = UUID::v4(); $blockObj = new \stdClass(); $blockObj->type = 'legacy'; $blockObj->id = $uuid; $settings = new \stdClass(); $settings->html = $block['content']; $blockObj->settings = $settings; $json = json_encode([$blockObj]); $this->updateSQL('blocks', ['json_content' => $json], ['id' => $block['id']]); if ($blocks_translations) { foreach (sqlQuery('SELECT id, content FROM blocks_translations WHERE id_block='.$id_block) as $block_tr) { $blockObj = new \stdClass(); $blockObj->type = 'legacy'; $blockObj->id = $uuid; $settings = new \stdClass(); $settings->html = $block_tr['content']; $blockObj->settings = $settings; $json = json_encode([$blockObj]); $this->updateSQL('blocks_translations', ['json_content' => $json], ['id' => $block_tr['id']]); } } } $this->upgradeOK(); } public function check_PhotosBlocksNewRelation() { return $this->checkTableExists('photos_blocks_new_relation'); } /** add photos_blocks_new_relation */ public function upgrade_PhotosBlocksNewRelation() { sqlQuery(' CREATE TABLE photos_blocks_new_relation ( id_photo INT UNSIGNED, `id_block` int(11) UNSIGNED DEFAULT NULL, position int null, CONSTRAINT id_photo UNIQUE (id_photo, id_block), FOREIGN KEY (id_photo) REFERENCES photos (id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (id_block) REFERENCES blocks (id) ON UPDATE CASCADE ON DELETE CASCADE )'); $this->upgradeOK(); } public function check_BlocksDateUpdatedColumn(): bool { return $this->checkColumnExists('blocks', 'date_updated'); } /** Add `blocks.date_updated` column */ public function upgrade_BlocksDateUpdatedColumn(): void { sqlQuery('ALTER TABLE blocks ADD COLUMN date_updated DATETIME DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP AFTER position;'); $this->upgradeOK(); } }