/** * Run database migrations * * @return void */ public static function run() { $database = \Database::getInstance(); // Copy license key from extension repository if (!\Config::get('rocksolid_slider_license') && $database->tableExists('tl_repository_installs') && $database->fieldExists('lickey', 'tl_repository_installs') && $database->fieldExists('extension', 'tl_repository_installs')) { $result = $database->prepare('SELECT lickey FROM tl_repository_installs WHERE extension = \'rocksolid-slider-pro\'')->execute(); if ($result && Slider::checkLicense((string) $result->lickey)) { \Config::getInstance()->add('$GLOBALS[\'TL_CONFIG\'][\'rocksolid_slider_license\']', (string) $result->lickey); } } // Fix the singleSRC data type for Contao 3.1 and below if (version_compare(VERSION, '3.2', '<') && $database->tableExists('tl_rocksolid_slide')) { $fields = $database->listFields('tl_rocksolid_slide'); foreach ($fields as $field) { if ($field['name'] === 'singleSRC' && $field['type'] !== 'varchar') { $database->query('ALTER TABLE tl_rocksolid_slide CHANGE singleSRC singleSRC varchar(255) NOT NULL default \'\''); $database->query('UPDATE tl_rocksolid_slide SET singleSRC = trim(trailing CHAR(0x00) from singleSRC)'); } } } // Update the multiSRC and orderSRC field from IDs to UUIDs if (version_compare(VERSION, '3.2', '>=') && $database->tableExists('tl_rocksolid_slider')) { $needUpdate = true; $result = $database->prepare('SELECT multiSRC FROM tl_rocksolid_slider WHERE multiSRC != \'\'')->execute(); if (!$result->count()) { $needUpdate = false; } while ($result->next()) { foreach (deserialize($result->multiSRC, true) as $value) { if (\Validator::isUuid($value)) { $needUpdate = false; break 2; } } } if ($needUpdate) { \Database\Updater::convertMultiField('tl_rocksolid_slider', 'multiSRC'); \Database\Updater::convertOrderField('tl_rocksolid_slider', 'orderSRC'); } } // Update the singleSRC field from IDs to UUIDs if (version_compare(VERSION, '3.2', '>=') && $database->tableExists('tl_rocksolid_slide')) { $fields = $database->listFields('tl_rocksolid_slide'); foreach ($fields as $field) { if ($field['name'] === 'singleSRC' && $field['type'] !== 'binary') { \Database\Updater::convertSingleField('tl_rocksolid_slide', 'singleSRC'); } } } }
/** * Run database migrations * * @return void */ public static function run() { $database = \Database::getInstance(); // Copy license key from extension repository if (!\Config::get('rocksolid_slider_license') && $database->tableExists('tl_repository_installs') && $database->fieldExists('lickey', 'tl_repository_installs') && $database->fieldExists('extension', 'tl_repository_installs')) { $result = $database->prepare('SELECT lickey FROM tl_repository_installs WHERE extension = \'rocksolid-slider-pro\'')->execute(); if ($result && $result->lickey && class_exists('MadeYourDay\\Contao\\Slider') && Slider::checkLicense((string) $result->lickey)) { \Config::getInstance()->add('$GLOBALS[\'TL_CONFIG\'][\'rocksolid_slider_license\']', (string) $result->lickey); } } // Fix the singleSRC data type for Contao 3.1 and below if (version_compare(VERSION, '3.2', '<') && $database->tableExists('tl_rocksolid_slide')) { $fields = $database->listFields('tl_rocksolid_slide'); foreach ($fields as $field) { if ($field['name'] === 'singleSRC' && $field['type'] !== 'varchar') { $database->query('ALTER TABLE tl_rocksolid_slide CHANGE singleSRC singleSRC varchar(255) NOT NULL default \'\''); $database->query('UPDATE tl_rocksolid_slide SET singleSRC = trim(trailing CHAR(0x00) from singleSRC)'); } } } // Update the multiSRC and orderSRC field from IDs to UUIDs if (version_compare(VERSION, '3.2', '>=') && $database->tableExists('tl_rocksolid_slider')) { $needUpdate = true; $result = $database->prepare('SELECT multiSRC FROM tl_rocksolid_slider WHERE multiSRC != \'\'')->execute(); if (!$result->count()) { $needUpdate = false; } while ($result->next()) { foreach (deserialize($result->multiSRC, true) as $value) { if (\Validator::isUuid($value)) { $needUpdate = false; break 2; } } } if ($needUpdate) { \Database\Updater::convertMultiField('tl_rocksolid_slider', 'multiSRC'); \Database\Updater::convertOrderField('tl_rocksolid_slider', 'orderSRC'); } } // Update the singleSRC field from IDs to UUIDs if (version_compare(VERSION, '3.2', '>=') && $database->tableExists('tl_rocksolid_slide')) { $fields = $database->listFields('tl_rocksolid_slide'); foreach ($fields as $field) { if ($field['name'] === 'singleSRC' && $field['type'] !== 'binary') { \Database\Updater::convertSingleField('tl_rocksolid_slide', 'singleSRC'); } } } // Initialize the slider type field if ($database->tableExists('tl_rocksolid_slider') && $database->tableExists('tl_rocksolid_slide') && $database->fieldExists('pid', 'tl_rocksolid_slide')) { if (!$database->fieldExists('type', 'tl_rocksolid_slider')) { $database->query('ALTER TABLE tl_rocksolid_slider ADD type varchar(255) NOT NULL default \'\''); } if ($database->prepare('SELECT id FROM tl_rocksolid_slider WHERE type = \'\'')->execute()->count()) { $database->query("UPDATE tl_rocksolid_slider\n\t\t\t\t\tSET type = CASE\n\t\t\t\t\t\tWHEN EXISTS (SELECT id FROM tl_rocksolid_slide\n\t\t\t\t\t\t\tWHERE tl_rocksolid_slide.pid = tl_rocksolid_slider.id\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tTHEN 'content'\n\t\t\t\t\t\tELSE 'image'\n\t\t\t\t\tEND\n\t\t\t\t\tWHERE type = ''\n\t\t\t\t"); } } // Initialize the slide type field if ($database->tableExists('tl_rocksolid_slide') && $database->tableExists('tl_content') && $database->fieldExists('pid', 'tl_content') && $database->fieldExists('ptable', 'tl_content')) { if (!$database->fieldExists('type', 'tl_rocksolid_slide')) { $database->query('ALTER TABLE tl_rocksolid_slide ADD type varchar(255) NOT NULL default \'\''); } if ($database->prepare('SELECT id FROM tl_rocksolid_slide WHERE type = \'\'')->execute()->count()) { $database->query("UPDATE tl_rocksolid_slide\n\t\t\t\t\tSET type = CASE\n\t\t\t\t\t\tWHEN EXISTS (SELECT id FROM tl_content\n\t\t\t\t\t\t\tWHERE tl_content.ptable = 'tl_rocksolid_slide'\n\t\t\t\t\t\t\tAND tl_content.pid = tl_rocksolid_slide.id\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tTHEN 'content'\n\t\t\t\t\t\tWHEN videoURL != '' OR videos IS NOT NULL\n\t\t\t\t\t\t\tTHEN 'video'\n\t\t\t\t\t\tELSE 'image'\n\t\t\t\t\tEND\n\t\t\t\t\tWHERE type = ''\n\t\t\t\t"); } } }