-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.php
42 lines (36 loc) · 2.54 KB
/
update.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
// 3.0.1 Database update: set priorities
$sql = rex_sql::factory();
$sql->setQuery('SHOW COLUMNS FROM '. \rex::getTablePrefix() ."d2u_courses_categories LIKE 'priority';");
if (0 === $sql->getRows()) {
$sql->setQuery('ALTER TABLE `'. \rex::getTablePrefix() .'d2u_courses_categories` ADD `priority` INT(10) NULL DEFAULT 0 AFTER `parent_category_id`;');
$sql->setQuery('SELECT category_id FROM `'. \rex::getTablePrefix() .'d2u_courses_categories` ORDER BY name;');
$update_sql = rex_sql::factory();
for ($i = 1; $i <= $sql->getRows(); ++$i) {
$update_sql->setQuery('UPDATE `'. \rex::getTablePrefix() .'d2u_courses_categories` SET priority = '. $i .' WHERE category_id = '. $sql->getValue('category_id') .';');
$sql->next();
}
}
// Update database to 3.0.5: convert updatedate to DATETIME
if (rex_version::compare($this->getVersion(), '3.0.5', '<')) { /** @phpstan-ignore-line */
$sql->setQuery('ALTER TABLE '. \rex::getTablePrefix() .'d2u_courses_categories ADD COLUMN `updatedate_new` DATETIME NOT NULL AFTER `updatedate`;');
$sql->setQuery('UPDATE '. \rex::getTablePrefix() .'d2u_courses_categories SET `updatedate_new` = FROM_UNIXTIME(`updatedate`);');
$sql->setQuery('ALTER TABLE '. \rex::getTablePrefix() .'d2u_courses_categories DROP updatedate;');
$sql->setQuery('ALTER TABLE '. \rex::getTablePrefix() .'d2u_courses_categories CHANGE `updatedate_new` `updatedate` DATETIME NOT NULL;');
$sql->setQuery('ALTER TABLE '. \rex::getTablePrefix() .'d2u_courses_courses ADD COLUMN `updatedate_new` DATETIME NOT NULL AFTER `updatedate`;');
$sql->setQuery('UPDATE '. \rex::getTablePrefix() .'d2u_courses_courses SET `updatedate_new` = FROM_UNIXTIME(`updatedate`);');
$sql->setQuery('ALTER TABLE '. \rex::getTablePrefix() .'d2u_courses_courses DROP updatedate;');
$sql->setQuery('ALTER TABLE '. \rex::getTablePrefix() .'d2u_courses_courses CHANGE `updatedate_new` `updatedate` DATETIME NOT NULL;');
}
// 3.0.1 Config Update
if (!rex_config::has('d2u_courses', 'payment_options')) {
rex_config::set('d2u_courses', 'payment_options', ['bank_transfer', 'cash', 'direct_debit']);
}
// Remove old translations
if (rex_version::compare(rex_addon::get('d2u_courses')->getVersion(), '3.3.0', '<')) {
if (rex_addon::get('sprog')->isAvailable()) {
$sql->setQuery('DELETE FROM '. \rex::getTablePrefix() ."sprog_wildcard WHERE wildcard = 'd2u_courses_cart_heading'");
}
}
// use path relative to __DIR__ to get correct path in update temp dir
$this->includeFile(__DIR__.'/install.php'); /** @phpstan-ignore-line */