Skip to content

Commit

Permalink
Added update script for Contao 3.2 UUIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Nov 25, 2013
1 parent ce4e31d commit 53c97d4
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/MadeYourDay/Contao/SliderRunonce.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,56 @@ abstract class SliderRunonce
*/
public static function run()
{
$database = \Database::getInstance();

// 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');
}
}
}
}
}

0 comments on commit 53c97d4

Please sign in to comment.