Splitting up migrations.... partway done

master
Mike Koch 7 years ago
parent bc752ff2c3
commit 311697693f
No known key found for this signature in database
GPG Key ID: 9BA5D7F8391455ED

@ -28,8 +28,8 @@ if (hesk_dbNumRows($tableSql) > 0) {
$migration_map = array(
// Pre-1.4.0 to 1.5.0 did not have a settings table
'1.6.0' => 16, '1.6.1' => 17, '1.7.0' => 21, '2.0.0' => 27, '2.0.1' => 28, '2.1.0' => 29, '2.1.1' => 31,
'2.2.0' => 34, '2.2.1' => 35, '2.3.0' => 41, '2.3.1' => 42, '2.3.2' => 43, '2.4.0' => 48, '2.4.1' => 49,
'1.6.0' => 22, '1.6.1' => 23, '1.7.0' => 27, '2.0.0' => 37, '2.0.1' => 38, '2.1.0' => 39, '2.1.1' => 42,
'2.2.0' => 47, '2.2.1' => 48, '2.3.0' => 68, '2.3.1' => 69, '2.3.2' => 70, /*TODO */ '2.4.0' => 48, '2.4.1' => 49,
'2.4.2' => 50, '2.5.0' => 54, '2.5.1' => 55, '2.5.2' => 56, '2.5.3' => 57, '2.5.4' => 58, '2.5.5' => 59,
'2.6.0' => 66, '2.6.1' => 67, '2.6.2' => 69, '2.6.3' => 70, '2.6.4' => 71, '3.0.0' => 75, '3.0.1' => 76,
'3.0.2' => 78, '3.0.3' => 79, '3.0.4' => 80, '3.0.5' => 81, '3.0.6' => 82, '3.0.7' => 83, '3.1.0' => 90,
@ -41,13 +41,13 @@ if (hesk_dbNumRows($tableSql) > 0) {
// migration # => sql for checking
$versionChecks = array(
// 1.5.0 -> users.active
9 => "SHOW COLUMNS FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` LIKE 'active'",
14 => "SHOW COLUMNS FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` LIKE 'active'",
// 1.4.1 -> denied_emails
6 => "SHOW TABLES LIKE '" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails'",
11 => "SHOW TABLES LIKE '" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails'",
// 1.4.0 -> denied ips
4 => "SHOW TABLES LIKE '" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips'",
9 => "SHOW TABLES LIKE '" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips'",
// Pre-1.4.0 but still something -> statuses
2 => "SHOW TABLES LIKE '" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses'"
7 => "SHOW TABLES LIKE '" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses'"
);
foreach ($versionChecks as $migrationNumber => $sql) {

@ -0,0 +1,16 @@
<?php
namespace Pre140\Statuses;
use AbstractMigration;
class AddIntColumnUpDropTableDown extends AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` ADD COLUMN `status_int` INT NOT NULL DEFAULT 0 AFTER `status`;");
}
function down($hesk_settings) {
$this->executeQuery("DROP TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses`");
}
}

@ -0,0 +1,28 @@
<?php
namespace Pre140\Statuses;
class CreateStatusesTable extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("CREATE TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` (
`ID` INT NOT NULL,
`ShortNameContentKey` TEXT NOT NULL,
`TicketViewContentKey` TEXT NOT NULL,
`TextColor` TEXT NOT NULL,
`IsNewTicketStatus` INT NOT NULL DEFAULT 0,
`IsClosed` INT NOT NULL DEFAULT 0,
`IsClosedByClient` INT NOT NULL DEFAULT 0,
`IsCustomerReplyStatus` INT NOT NULL DEFAULT 0,
`IsStaffClosedOption` INT NOT NULL DEFAULT 0,
`IsStaffReopenedStatus` INT NOT NULL DEFAULT 0,
`IsDefaultStaffReplyStatus` INT NOT NULL DEFAULT 0,
`LockedTicketStatus` INT NOT NULL DEFAULT 0,
PRIMARY KEY (`ID`))");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` ADD COLUMN `status_int` INT NOT NULL AFTER `status`;");
}
}

@ -0,0 +1,21 @@
<?php
namespace Pre140\Statuses;
use AbstractMigration;
class DropOldStatusColumn extends AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` DROP COLUMN `status`");
}
function down($hesk_settings) {
$ticketsRS = $this->executeQuery("SELECT `id`, `status` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets`;");
while ($currentResult = hesk_dbFetchAssoc($ticketsRS)) {
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `status_int` = '" . intval($currentResult['status']) . "' WHERE `id` = " . $currentResult['id']);
}
}
}

@ -0,0 +1,32 @@
<?php
namespace Pre140\Statuses;
class InsertStatusRecords extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` (ID, ShortNameContentKey, TicketViewContentKey, TextColor, IsNewTicketStatus, IsClosed, IsClosedByClient, IsCustomerReplyStatus,
IsStaffClosedOption, IsStaffReopenedStatus, IsDefaultStaffReplyStatus, LockedTicketStatus)
VALUES (0, 'open', 'open', '#FF0000', 1, 0, 0, 0, 0, 0, 0, 0);");
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` (ID, ShortNameContentKey, TicketViewContentKey, TextColor, IsNewTicketStatus, IsClosed, IsClosedByClient, IsCustomerReplyStatus,
IsStaffClosedOption, IsStaffReopenedStatus, IsDefaultStaffReplyStatus, LockedTicketStatus)
VALUES (1, 'wait_reply', 'wait_staff_reply', '#FF9933', 0, 0, 0, 1, 0, 1, 0, 0);");
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` (ID, ShortNameContentKey, TicketViewContentKey, TextColor, IsNewTicketStatus, IsClosed, IsClosedByClient, IsCustomerReplyStatus,
IsStaffClosedOption, IsStaffReopenedStatus, IsDefaultStaffReplyStatus, LockedTicketStatus)
VALUES (2, 'replied', 'wait_cust_reply', '#0000FF', 0, 0, 0, 0, 0, 0, 1, 0);");
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` (ID, ShortNameContentKey, TicketViewContentKey, TextColor, IsNewTicketStatus, IsClosed, IsClosedByClient, IsCustomerReplyStatus,
IsStaffClosedOption, IsStaffReopenedStatus, IsDefaultStaffReplyStatus, LockedTicketStatus)
VALUES (3, 'resolved', 'resolved', '#008000', 0, 1, 1, 0, 1, 0, 0, 1);");
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` (ID, ShortNameContentKey, TicketViewContentKey, TextColor, IsNewTicketStatus, IsClosed, IsClosedByClient, IsCustomerReplyStatus,
IsStaffClosedOption, IsStaffReopenedStatus, IsDefaultStaffReplyStatus, LockedTicketStatus)
VALUES (4, 'in_progress', 'in_progress', '#000000', 0, 0, 0, 0, 0, 0, 0, 0);");
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` (ID, ShortNameContentKey, TicketViewContentKey, TextColor, IsNewTicketStatus, IsClosed, IsClosedByClient, IsCustomerReplyStatus,
IsStaffClosedOption, IsStaffReopenedStatus, IsDefaultStaffReplyStatus, LockedTicketStatus)
VALUES (5, 'on_hold', 'on_hold', '#000000', 0, 0, 0, 0, 0, 0, 0, 0);");
}
function down($hesk_settings) {
}
}

@ -0,0 +1,20 @@
<?php
namespace Pre140\Statuses;
use AbstractMigration;
class MoveStatusesToNewColumn extends AbstractMigration {
function up($hesk_settings) {
$ticketsRS = $this->executeQuery("SELECT `id`, `status` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets`;");
while ($currentResult = hesk_dbFetchAssoc($ticketsRS)) {
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `status_int` = " . $currentResult['status'] . " WHERE `id` = " . $currentResult['id']);
}
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` CHANGE COLUMN `status_int` `status` INT NOT NULL");
}
}

@ -0,0 +1,15 @@
<?php
namespace Pre140\Statuses;
class RenameTempColumn extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` CHANGE COLUMN `status_int` `status` INT NOT NULL");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` DROP COLUMN `status`");
}
}

@ -1,72 +0,0 @@
<?php
namespace Pre140;
use AbstractMigration;
class StatusesMigration extends AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` ADD COLUMN `status_int` INT NOT NULL DEFAULT 0 AFTER `status`;");
$ticketsRS = $this->executeQuery("SELECT `id`, `status` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets`;");
while ($currentResult = hesk_dbFetchAssoc($ticketsRS)) {
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `status_int` = " . $currentResult['status'] . " WHERE `id` = " . $currentResult['id']);
}
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` DROP COLUMN `status`");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` CHANGE COLUMN `status_int` `status` INT NOT NULL");
$this->executeQuery("CREATE TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` (
`ID` INT NOT NULL,
`ShortNameContentKey` TEXT NOT NULL,
`TicketViewContentKey` TEXT NOT NULL,
`TextColor` TEXT NOT NULL,
`IsNewTicketStatus` INT NOT NULL DEFAULT 0,
`IsClosed` INT NOT NULL DEFAULT 0,
`IsClosedByClient` INT NOT NULL DEFAULT 0,
`IsCustomerReplyStatus` INT NOT NULL DEFAULT 0,
`IsStaffClosedOption` INT NOT NULL DEFAULT 0,
`IsStaffReopenedStatus` INT NOT NULL DEFAULT 0,
`IsDefaultStaffReplyStatus` INT NOT NULL DEFAULT 0,
`LockedTicketStatus` INT NOT NULL DEFAULT 0,
PRIMARY KEY (`ID`))");
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` (ID, ShortNameContentKey, TicketViewContentKey, TextColor, IsNewTicketStatus, IsClosed, IsClosedByClient, IsCustomerReplyStatus,
IsStaffClosedOption, IsStaffReopenedStatus, IsDefaultStaffReplyStatus, LockedTicketStatus)
VALUES (0, 'open', 'open', '#FF0000', 1, 0, 0, 0, 0, 0, 0, 0);");
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` (ID, ShortNameContentKey, TicketViewContentKey, TextColor, IsNewTicketStatus, IsClosed, IsClosedByClient, IsCustomerReplyStatus,
IsStaffClosedOption, IsStaffReopenedStatus, IsDefaultStaffReplyStatus, LockedTicketStatus)
VALUES (1, 'wait_reply', 'wait_staff_reply', '#FF9933', 0, 0, 0, 1, 0, 1, 0, 0);");
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` (ID, ShortNameContentKey, TicketViewContentKey, TextColor, IsNewTicketStatus, IsClosed, IsClosedByClient, IsCustomerReplyStatus,
IsStaffClosedOption, IsStaffReopenedStatus, IsDefaultStaffReplyStatus, LockedTicketStatus)
VALUES (2, 'replied', 'wait_cust_reply', '#0000FF', 0, 0, 0, 0, 0, 0, 1, 0);");
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` (ID, ShortNameContentKey, TicketViewContentKey, TextColor, IsNewTicketStatus, IsClosed, IsClosedByClient, IsCustomerReplyStatus,
IsStaffClosedOption, IsStaffReopenedStatus, IsDefaultStaffReplyStatus, LockedTicketStatus)
VALUES (3, 'resolved', 'resolved', '#008000', 0, 1, 1, 0, 1, 0, 0, 1);");
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` (ID, ShortNameContentKey, TicketViewContentKey, TextColor, IsNewTicketStatus, IsClosed, IsClosedByClient, IsCustomerReplyStatus,
IsStaffClosedOption, IsStaffReopenedStatus, IsDefaultStaffReplyStatus, LockedTicketStatus)
VALUES (4, 'in_progress', 'in_progress', '#000000', 0, 0, 0, 0, 0, 0, 0, 0);");
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` (ID, ShortNameContentKey, TicketViewContentKey, TextColor, IsNewTicketStatus, IsClosed, IsClosedByClient, IsCustomerReplyStatus,
IsStaffClosedOption, IsStaffReopenedStatus, IsDefaultStaffReplyStatus, LockedTicketStatus)
VALUES (5, 'on_hold', 'on_hold', '#000000', 0, 0, 0, 0, 0, 0, 0, 0);");
$keyRs = $this->executeQuery("SHOW KEYS FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` WHERE Key_name='statuses'");
if (hesk_dbNumRows($keyRs) == 0) {
//-- Add the key
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` ADD KEY `statuses` (`status`)");
}
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` ADD COLUMN `status_int` INT NOT NULL AFTER `status`;");
$ticketsRS = $this->executeQuery("SELECT `id`, `status` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets`;");
while ($currentResult = hesk_dbFetchAssoc($ticketsRS)) {
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `status_int` = '" . intval($currentResult['status']) . "' WHERE `id` = " . $currentResult['id']);
}
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` DROP COLUMN `status`");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` CHANGE COLUMN `status_int` `status` INT NOT NULL");
$this->executeQuery("DROP TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses`");
}
}

@ -18,66 +18,93 @@ spl_autoload_register(function ($class) {
function getAllMigrations() {
return array(
1 => new \Pre140\StatusesMigration(),
1 => new \Pre140\Statuses\AddIntColumnUpDropTableDown(),
2 => new \Pre140\Statuses\MoveStatusesToNewColumn(),
3 => new \Pre140\Statuses\DropOldStatusColumn(),
4 => new \Pre140\Statuses\RenameTempColumn(),
5 => new \Pre140\Statuses\CreateStatusesTable(),
6 => new \Pre140\Statuses\InsertStatusRecords(),
//1.4.0
2 => new \v140\AddAutorefreshColumn(),
3 => new \v140\AddDeniedIpsTable(),
7 => new \v140\AddAutorefreshColumn(),
8 => new \v140\AddDeniedIpsTable(),
//1.4.1
4 => new \v141\AddDeniedEmailsTable(),
5 => new \v141\AddTicketParentColumn(),
9 => new \v141\AddDeniedEmailsTable(),
10 => new \v141\AddTicketParentColumn(),
//1.5.0
6 => new \v150\AddActiveColumnToUser(),
7 => new \v150\AddCanManSettingsPermissionToUser(),
8 => new \v150\AddDefaultNotifyCustomerEmailPreference(),
11 => new \v150\AddActiveColumnToUser(),
12 => new \v150\AddCanManSettingsPermissionToUser(),
13 => new \v150\AddDefaultNotifyCustomerEmailPreference(),
//1.6.0
9 => new \v160\AddNotifyNoteUnassignedProperty(),
10 => new \v160\AddCanChangeNotificationSettingsPermission(),
11 => new \v160\AddEditInfoToNotes(),
12 => new \v160\AddNoteIdToAttachments(),
13 => new \v160\ModifyTicketIdOnAttachments(),
14 => new \v160\CreateSettingsTable(),
15 => new \v160\InsertVersionRecord(),
14 => new \v160\AddNotifyNoteUnassignedProperty(),
15 => new \v160\AddCanChangeNotificationSettingsPermission(),
16 => new \v160\AddEditInfoToNotes\AddEditDateColumn(),
17 => new \v160\AddEditInfoToNotes\AddNumberOfEditsColumn(),
18 => new \v160\AddNoteIdToAttachments(),
19 => new \v160\ModifyTicketIdOnAttachments(),
20 => new \v160\CreateSettingsTable(),
21 => new \v160\InsertVersionRecord(),
//1.6.1
16 => new LegacyUpdateMigration('1.6.1', '1.6.0'),
22 => new LegacyUpdateMigration('1.6.1', '1.6.0'),
//1.7.0
17 => new \v170\CreateVerifiedEmailsTable(),
18 => new \v170\CreatePendingVerificationEmailsTable(),
19 => new \v170\CreateStageTicketsTable(),
20 => new LegacyUpdateMigration('1.7.0', '1.6.1'),
23 => new \v170\CreateVerifiedEmailsTable(),
24 => new \v170\CreatePendingVerificationEmailsTable(),
25 => new \v170\CreateStageTicketsTable(),
26 => new LegacyUpdateMigration('1.7.0', '1.6.1'),
//2.0.0
21 => new \v200\RemoveNoteIdFromAttachments(),
22 => new \v200\RemoveEditInfoFromNotes(),
23 => new \v200\RemoveDefaultNotifyCustomerEmailPreference(),
24 => new \v200\AddMissingKeyToTickets(),
25 => new \v200\MigrateIpAndEmailBans(),
26 => new LegacyUpdateMigration('2.0.0', '1.7.0'),
27 => new \v200\RemoveNoteIdFromAttachments(),
28 => new \v200\RemoveEditInfoFromNotes\DropEditDate(),
29 => new \v200\RemoveEditInfoFromNotes\DropNumberOfEditsColumn(),
30 => new \v200\RemoveDefaultNotifyCustomerEmailPreference(),
31 => new \v200\AddMissingKeyToTickets(),
32 => new \v200\MigrateIpAndEmailBans\InsertIpBans(),
33 => new \v200\MigrateIpAndEmailBans\InsertEmailBans(),
34 => new \v200\MigrateIpAndEmailBans\DropOldEmailBansTable(),
35 => new \v200\MigrateIpAndEmailBans\DropOldIpBansTable(),
36 => new LegacyUpdateMigration('2.0.0', '1.7.0'),
//2.0.1
27 => new LegacyUpdateMigration('2.0.1', '2.0.0'),
37 => new LegacyUpdateMigration('2.0.1', '2.0.0'),
//2.1.0
28 => new LegacyUpdateMigration('2.1.0', '2.0.1'),
38 => new LegacyUpdateMigration('2.1.0', '2.0.1'),
//2.1.1
29 => new \v211\FixStageTicketsTable(),
30 => new LegacyUpdateMigration('2.1.1', '2.1.0'),
39 => new \v211\FixStageTicketsTable\ChangeDtColumnType(),
40 => new \v211\FixStageTicketsTable\FixStageTicketsTable(),
41 => new LegacyUpdateMigration('2.1.1', '2.1.0'),
//2.2.0
31 => new \v220\AddIsAutocloseOptionToStatuses(),
32 => new \v220\AddClosableColumnToStatuses(),
33 => new LegacyUpdateMigration('2.2.0', '2.1.1'),
42 => new \v220\AddIsAutocloseOptionToStatuses\AddNewColumn(),
43 => new \v220\AddIsAutocloseOptionToStatuses\SetDefaultValue(),
44 => new \v220\AddClosableColumnToStatuses\AddNewColumn(),
45 => new \v220\AddClosableColumnToStatuses\SetDefaultValue(),
46 => new LegacyUpdateMigration('2.2.0', '2.1.1'),
//2.2.1
34 => new LegacyUpdateMigration('2.2.1', '2.2.0'),
47 => new LegacyUpdateMigration('2.2.1', '2.2.0'),
//2.3.0
35 => new \v230\AddIconToServiceMessages(),
36 => new \v230\ConsolidateStatusColumns(),
37 => new \v230\AddCoordinatesToTickets(),
38 => new \v230\AddCategoryManager(),
39 => new \v230\MovePermissionsToHeskPrivilegesColumn(),
40 => new \v230\CreatePermissionTemplates(),
41 => new LegacyUpdateMigration('2.3.0', '2.2.1'),
48 => new \v230\AddIconToServiceMessages(),
49 => new \v230\ConsolidateStatusColumns\AddKeyColumn(),
50 => new \v230\ConsolidateStatusColumns\SetNewKeyColumnValue(),
51 => new \v230\ConsolidateStatusColumns\DropShortNameColumn(),
52 => new \v230\ConsolidateStatusColumns\DropTicketViewContentKeyColumn(),
53 => new \v230\AddCoordinatesToTickets\AddLatitudeToTickets(),
54 => new \v230\AddCoordinatesToTickets\AddLongitudeToTickets(),
55 => new \v230\AddCoordinatesToTickets\AddLatitudeToStageTickets(),
56 => new \v230\AddCoordinatesToTickets\AddLongitudeToStageTickets(),
57 => new \v230\AddCategoryManager(),
58 => new \v230\CopyCanManSettings(),
59 => new \v230\CopyCanChangeNotificationSettings(),
60 => new \v230\DropCanManSettingsColumn(),
61 => new \v230\DropCanChangeNotificationSettingsColumn(),
62 => new \v230\CreatePermissionTemplates\AddPermissionTemplateColumn(),
63 => new \v230\CreatePermissionTemplates\CreatePermissionTemplatesTable(),
64 => new \v230\CreatePermissionTemplates\InsertAdminPermissionTemplate(),
65 => new \v230\CreatePermissionTemplates\InsertStaffPermissionTemplate(),
66 => new \v230\CreatePermissionTemplates\UpdateAdminUsersTemplate(),
67 => new LegacyUpdateMigration('2.3.0', '2.2.1'),
//2.3.1
42 => new LegacyUpdateMigration('2.3.1', '2.3.0'),
68 => new LegacyUpdateMigration('2.3.1', '2.3.0'),
//2.3.2
43 => new LegacyUpdateMigration('2.3.2', '2.3.1'),
69 => new LegacyUpdateMigration('2.3.2', '2.3.1'),
//2.4.0
44 => new \v240\CreateQuickHelpSectionsTable(),
70 => new \v240\CreateQuickHelpSectionsTable(),
// TODO
45 => new \v240\CreateNewStatusNameTable(),
46 => new \v240\AddDownloadCountToAttachments(),
47 => new \v240\AddHtmlColumnToTickets(),

@ -0,0 +1,14 @@
<?php
namespace v160\AddEditInfoToNotes;
class AddEditDateColumn extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` ADD COLUMN `edit_date` DATETIME NULL");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` DROP COLUMN `edit_date`");
}
}

@ -1,17 +1,15 @@
<?php
namespace v160;
namespace v160\AddEditInfoToNotes;
class AddEditInfoToNotes extends \AbstractMigration {
class AddNumberOfEditsColumn extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` ADD COLUMN `edit_date` DATETIME NULL");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` ADD COLUMN `number_of_edits` INT NOT NULL DEFAULT 0");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` DROP COLUMN `edit_date`");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` DROP COLUMN `number_of_edits`");
}
}

@ -1,50 +0,0 @@
<?php
namespace v200;
class MigrateIpAndEmailBans extends \AbstractMigration {
function up($hesk_settings) {
// Insert the email bans
$emailBanRS = $this->executeQuery("SELECT `Email` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails`");
while ($row = hesk_dbFetchAssoc($emailBanRS)) {
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_emails` (`email`, `banned_by`, `dt`)
VALUES ('" . hesk_dbEscape($row['Email']) . "', 1, NOW())");
}
// Insert the IP bans
$ipBanRS = $this->executeQuery("SELECT `RangeStart`, `RangeEnd` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips`");
while ($row = hesk_dbFetchAssoc($ipBanRS)) {
$ipFrom = long2ip($row['RangeStart']);
$ipTo = long2ip($row['RangeEnd']);
$ipDisplay = $ipFrom == $ipTo ? $ipFrom : $ipFrom . ' - ' . $ipTo;
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_ips` (`ip_from`, `ip_to`, `ip_display`, `banned_by`, `dt`)
VALUES (" . $row['RangeStart'] . ", " . $row['RangeEnd'] . ", '" . $ipDisplay . "', 1, NOW())");
}
// Migration Complete. Drop Tables.
$this->executeQuery("DROP TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips`");
$this->executeQuery("DROP TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails`");
}
function down($hesk_settings) {
$this->executeQuery("CREATE TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips` (
`ID` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
`RangeStart` VARCHAR(100) NOT NULL,
`RangeEnd` VARCHAR(100) NOT NULL)");
$this->executeQuery("CREATE TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails` (
ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
Email VARCHAR(100) NOT NULL);");
$emails = $this->executeQuery("SELECT `email` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_emails`");
while ($row = hesk_dbFetchAssoc($emails)) {
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails` (Email) VALUES ('" . hesk_dbEscape($row['email']) . "')");
}
$ips = $this->executeQuery("SELECT `ip_from`, `ip_to` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_ips`");
while ($row = hesk_dbFetchAssoc($ips)) {
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips` (`RangeStart`, `RangeEnd`) VALUES (" . $row['ip_from'] . ", " . $row['ip_to'] . ")");
}
}
}

@ -0,0 +1,17 @@
<?php
namespace v200\MigrateIpAndEmailBans;
class DropOldEmailBansTable extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("DROP TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails`");
}
function down($hesk_settings) {
$this->executeQuery("CREATE TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails` (
ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
Email VARCHAR(100) NOT NULL);");
}
}

@ -0,0 +1,18 @@
<?php
namespace v200\MigrateIpAndEmailBans;
class DropOldIpBansTable extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("DROP TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips`");
}
function down($hesk_settings) {
$this->executeQuery("CREATE TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips` (
`ID` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
`RangeStart` VARCHAR(100) NOT NULL,
`RangeEnd` VARCHAR(100) NOT NULL)");
}
}

@ -0,0 +1,21 @@
<?php
namespace v200\MigrateIpAndEmailBans;
class InsertEmailBans extends \AbstractMigration {
function up($hesk_settings) {
$emailBanRS = $this->executeQuery("SELECT `Email` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails`");
while ($row = hesk_dbFetchAssoc($emailBanRS)) {
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_emails` (`email`, `banned_by`, `dt`)
VALUES ('" . hesk_dbEscape($row['Email']) . "', 1, NOW())");
}
}
function down($hesk_settings) {
$emails = $this->executeQuery("SELECT `email` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_emails`");
while ($row = hesk_dbFetchAssoc($emails)) {
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails` (Email) VALUES ('" . hesk_dbEscape($row['email']) . "')");
}
}
}

@ -0,0 +1,25 @@
<?php
namespace v200\MigrateIpAndEmailBans;
class InsertIpBans extends \AbstractMigration {
function up($hesk_settings) {
$ipBanRS = $this->executeQuery("SELECT `RangeStart`, `RangeEnd` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips`");
while ($row = hesk_dbFetchAssoc($ipBanRS)) {
$ipFrom = long2ip($row['RangeStart']);
$ipTo = long2ip($row['RangeEnd']);
$ipDisplay = $ipFrom == $ipTo ? $ipFrom : $ipFrom . ' - ' . $ipTo;
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_ips` (`ip_from`, `ip_to`, `ip_display`, `banned_by`, `dt`)
VALUES (" . $row['RangeStart'] . ", " . $row['RangeEnd'] . ", '" . $ipDisplay . "', 1, NOW())");
}
}
function down($hesk_settings) {
$ips = $this->executeQuery("SELECT `ip_from`, `ip_to` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_ips`");
while ($row = hesk_dbFetchAssoc($ips)) {
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips` (`RangeStart`, `RangeEnd`) VALUES (" . $row['ip_from'] . ", " . $row['ip_to'] . ")");
}
}
}

@ -0,0 +1,14 @@
<?php
namespace v200\RemoveEditInfoFromNotes;
class DropEditDate extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` DROP COLUMN `edit_date`");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` ADD COLUMN `edit_date` DATETIME NULL");
}
}

@ -1,17 +1,15 @@
<?php
namespace v200;
namespace v200\RemoveEditInfoFromNotes;
class RemoveEditInfoFromNotes extends \AbstractMigration {
class DropNumberOfEditsColumn extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` DROP COLUMN `edit_date`");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` DROP COLUMN `number_of_edits`");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` ADD COLUMN `edit_date` DATETIME NULL");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` ADD COLUMN `number_of_edits` INT NOT NULL DEFAULT 0");
}
}

@ -0,0 +1,14 @@
<?php
namespace v211\FixStageTicketsTable;
class ChangeDtColumnType extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "stage_tickets` CHANGE `dt` `dt` TIMESTAMP NOT NULL DEFAULT '2000-01-01 00:00:00'");
}
function down($hesk_settings) {
// NOOP
}
}

@ -1,11 +1,10 @@
<?php
namespace v211;
namespace v211\FixStageTicketsTable;
class FixStageTicketsTable extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "stage_tickets` CHANGE `dt` `dt` TIMESTAMP NOT NULL DEFAULT '2000-01-01 00:00:00'");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "stage_tickets`
CHANGE `email` `email` VARCHAR( 1000 ) NOT NULL DEFAULT '',
CHANGE `ip` `ip` VARCHAR(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '',

@ -1,13 +1,12 @@
<?php
namespace v220;
namespace v220\AddClosableColumnToStatuses;
class AddClosableColumnToStatuses extends \AbstractMigration {
class AddNewColumn extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` ADD COLUMN `Closable` VARCHAR(10) NOT NULL");
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` SET `Closable` = 'yes'");
}
function down($hesk_settings) {

@ -0,0 +1,15 @@
<?php
namespace v220\AddClosableColumnToStatuses;
class SetDefaultValue extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` SET `Closable` = 'yes'");
}
function down($hesk_settings) {
// no-op
}
}

@ -1,12 +1,11 @@
<?php
namespace v220;
namespace v220\AddIsAutocloseOptionToStatuses;
class AddIsAutocloseOptionToStatuses extends \AbstractMigration {
class AddNewColumn extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` ADD COLUMN `IsAutocloseOption` INT NOT NULL DEFAULT 0");
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` SET `IsAutocloseOption` = 1 WHERE `IsStaffClosedOption` = 1");
}
function down($hesk_settings) {

@ -0,0 +1,14 @@
<?php
namespace v220\AddIsAutocloseOptionToStatuses;
class SetDefaultValue extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` SET `IsAutocloseOption` = 1 WHERE `IsStaffClosedOption` = 1");
}
function down($hesk_settings) {
// no-op
}
}

@ -1,21 +0,0 @@
<?php
namespace v230;
class AddCoordinatesToTickets extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` ADD COLUMN `latitude` VARCHAR(100) NOT NULL DEFAULT 'E-0'");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` ADD COLUMN `longitude` VARCHAR(100) NOT NULL DEFAULT 'E-0'");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "stage_tickets` ADD COLUMN `latitude` VARCHAR(100) NOT NULL DEFAULT 'E-0'");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "stage_tickets` ADD COLUMN `longitude` VARCHAR(100) NOT NULL DEFAULT 'E-0'");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` DROP COLUMN `latitude`");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` DROP COLUMN `longitude`");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "stage_tickets` DROP COLUMN `latitude`");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "stage_tickets` DROP COLUMN `longitude`");
}
}

@ -0,0 +1,15 @@
<?php
namespace v230\AddCoordinatesToTickets;
class AddLatitudeToStageTickets extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "stage_tickets` ADD COLUMN `latitude` VARCHAR(100) NOT NULL DEFAULT 'E-0'");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "stage_tickets` DROP COLUMN `latitude`");
}
}

@ -0,0 +1,15 @@
<?php
namespace v230\AddCoordinatesToTickets;
class AddLatitudeToTickets extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` ADD COLUMN `latitude` VARCHAR(100) NOT NULL DEFAULT 'E-0'");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` DROP COLUMN `latitude`");
}
}

@ -0,0 +1,15 @@
<?php
namespace v230\AddCoordinatesToTickets;
class AddLongitudeToStageTickets extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "stage_tickets` ADD COLUMN `longitude` VARCHAR(100) NOT NULL DEFAULT 'E-0'");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "stage_tickets` DROP COLUMN `longitude`");
}
}

@ -0,0 +1,15 @@
<?php
namespace v230\AddCoordinatesToTickets;
class AddLongitudeToTickets extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` ADD COLUMN `longitude` VARCHAR(100) NOT NULL DEFAULT 'E-0'");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` DROP COLUMN `longitude`");
}
}

@ -1,21 +0,0 @@
<?php
namespace v230;
class ConsolidateStatusColumns extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` ADD COLUMN `Key` TEXT");
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` SET `Key` = `ShortNameContentKey`");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` DROP COLUMN `ShortNameContentKey`");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` DROP COLUMN `TicketViewContentKey`");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` ADD COLUMN `TicketViewContentKey` TEXT");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` ADD COLUMN `ShortNameContentKey` TEXT");
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` SET `TicketViewContentKey` = `Key`, `ShortNameContentKey` = `Key`");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` DROP COLUMN `Key`");
}
}

@ -0,0 +1,15 @@
<?php
namespace v230\ConsolidateStatusColumns;
class AddKeyColumn extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` ADD COLUMN `Key` TEXT");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` DROP COLUMN `Key`");
}
}

@ -0,0 +1,15 @@
<?php
namespace v230\ConsolidateStatusColumns;
class DropShortNameColumn extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` DROP COLUMN `ShortNameContentKey`");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` ADD COLUMN `ShortNameContentKey` TEXT");
}
}

@ -0,0 +1,15 @@
<?php
namespace v230\ConsolidateStatusColumns;
class DropTicketViewContentKeyColumn extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` DROP COLUMN `TicketViewContentKey`");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` ADD COLUMN `TicketViewContentKey` TEXT");
}
}

@ -0,0 +1,15 @@
<?php
namespace v230\ConsolidateStatusColumns;
class SetNewKeyColumnValue extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` SET `Key` = `ShortNameContentKey`");
}
function down($hesk_settings) {
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` SET `TicketViewContentKey` = `Key`, `ShortNameContentKey` = `Key`");
}
}

@ -1,25 +0,0 @@
<?php
namespace v230;
class CreatePermissionTemplates extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` ADD COLUMN `permission_template` INT");
$this->executeQuery("CREATE TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "permission_templates` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(255) NOT NULL,
`heskprivileges` VARCHAR(1000),
`categories` VARCHAR(500))");
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "permission_templates` (`name`, `heskprivileges`, `categories`)
VALUES ('Administrator', 'ALL', 'ALL')");
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "permission_templates` (`name`, `heskprivileges`, `categories`)
VALUES ('Staff', 'can_view_tickets,can_reply_tickets,can_change_cat,can_assign_self,can_view_unassigned,can_view_online', '1')");
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` SET `permission_template` = 1 WHERE `isadmin` = '1'");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` DROP COLUMN `permission_template`");
$this->executeQuery("DROP TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "permission_templates`");
}
}

@ -0,0 +1,15 @@
<?php
namespace v230\CreatePermissionTemplates;
class AddPermissionTemplateColumn extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` ADD COLUMN `permission_template` INT");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` DROP COLUMN `permission_template`");
}
}

@ -0,0 +1,18 @@
<?php
namespace v230\CreatePermissionTemplates;
class CreatePermissionTemplatesTable extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("CREATE TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "permission_templates` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(255) NOT NULL,
`heskprivileges` VARCHAR(1000),
`categories` VARCHAR(500))");
}
function down($hesk_settings) {
$this->executeQuery("DROP TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "permission_templates`");
}
}

@ -0,0 +1,15 @@
<?php
namespace v230\CreatePermissionTemplates;
class InsertAdminPermissionTemplate extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "permission_templates` (`name`, `heskprivileges`, `categories`)
VALUES ('Administrator', 'ALL', 'ALL')");
}
function down($hesk_settings) {
}
}

@ -0,0 +1,15 @@
<?php
namespace v230\CreatePermissionTemplates;
class InsertStaffPermissionTemplate extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "permission_templates` (`name`, `heskprivileges`, `categories`)
VALUES ('Staff', 'can_view_tickets,can_reply_tickets,can_change_cat,can_assign_self,can_view_unassigned,can_view_online', '1')");
}
function down($hesk_settings) {
}
}

@ -0,0 +1,14 @@
<?php
namespace v230\CreatePermissionTemplates;
class UpdateAdminUsersTemplate extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` SET `permission_template` = 1 WHERE `isadmin` = '1'");
}
function down($hesk_settings) {
}
}

@ -1,53 +0,0 @@
<?php
namespace v230;
class MovePermissionsToHeskPrivilegesColumn extends \AbstractMigration {
function up($hesk_settings) {
// Move can_manage_settings and can_change_notification_settings into the heskprivileges list
$res = $this->executeQuery("SELECT `id`, `heskprivileges` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` WHERE `isadmin` = '0'
AND `can_manage_settings` = '1'");
while ($row = hesk_dbFetchAssoc($res)) {
if ($row['heskprivileges'] != '') {
$currentPrivileges = explode(',', $row['heskprivileges']);
array_push($currentPrivileges, 'can_man_settings');
$newPrivileges = implode(',', $currentPrivileges);
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` SET `heskprivileges` = '" . hesk_dbEscape($newPrivileges) . "'
WHERE `id` = " . intval($row['id']));
} else {
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` SET `heskprivileges` = 'can_man_settings'
WHERE `id` = " . intval($row['id']));
}
}
$res = $this->executeQuery("SELECT `id`, `heskprivileges` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` WHERE `isadmin` = '0'
AND `can_change_notification_settings` = '1'");
while ($row = hesk_dbFetchAssoc($res)) {
if ($row['heskprivileges'] != '') {
$currentPrivileges = explode(',', $row['heskprivileges']);
array_push($currentPrivileges, 'can_change_notification_settings');
$newPrivileges = implode(',', $currentPrivileges);
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` SET `heskprivileges` = '" . hesk_dbEscape($newPrivileges) . "'
WHERE `id` = " . intval($row['id']));
} else {
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` SET `heskprivileges` = 'can_change_notification_settings'
WHERE `id` = " . intval($row['id']));
}
}
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` DROP COLUMN `can_manage_settings`");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` DROP COLUMN `can_change_notification_settings`");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` ADD COLUMN `can_change_notification_settings` ENUM('0', '1') NOT NULL DEFAULT '1'");
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` ADD COLUMN `can_manage_settings` ENUM ('0', '1') NOT NULL DEFAULT '1'");
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users`
SET `can_manage_settings` = '0'
WHERE `heskprivileges` NOT LIKE '%can_man_settings%'");
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users`
SET `can_change_notification_settings` = '0'
WHERE `heskprivileges` NOT LIKE '%can_change_notification_settings%'");
}
}

@ -0,0 +1,30 @@
<?php
namespace v230;
class CopyCanChangeNotificationSettings extends \AbstractMigration {
function up($hesk_settings) {
$res = $this->executeQuery("SELECT `id`, `heskprivileges` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` WHERE `isadmin` = '0'
AND `can_change_notification_settings` = '1'");
while ($row = hesk_dbFetchAssoc($res)) {
if ($row['heskprivileges'] != '') {
$currentPrivileges = explode(',', $row['heskprivileges']);
array_push($currentPrivileges, 'can_change_notification_settings');
$newPrivileges = implode(',', $currentPrivileges);
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` SET `heskprivileges` = '" . hesk_dbEscape($newPrivileges) . "'
WHERE `id` = " . intval($row['id']));
} else {
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` SET `heskprivileges` = 'can_change_notification_settings'
WHERE `id` = " . intval($row['id']));
}
}
}
function down($hesk_settings) {
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users`
SET `can_change_notification_settings` = '0'
WHERE `heskprivileges` NOT LIKE '%can_change_notification_settings%'");
}
}

@ -0,0 +1,31 @@
<?php
namespace v230;
class CopyCanManSettings extends \AbstractMigration {
function up($hesk_settings) {
// Move can_manage_settings and can_change_notification_settings into the heskprivileges list
$res = $this->executeQuery("SELECT `id`, `heskprivileges` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` WHERE `isadmin` = '0'
AND `can_manage_settings` = '1'");
while ($row = hesk_dbFetchAssoc($res)) {
if ($row['heskprivileges'] != '') {
$currentPrivileges = explode(',', $row['heskprivileges']);
array_push($currentPrivileges, 'can_man_settings');
$newPrivileges = implode(',', $currentPrivileges);
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` SET `heskprivileges` = '" . hesk_dbEscape($newPrivileges) . "'
WHERE `id` = " . intval($row['id']));
} else {
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` SET `heskprivileges` = 'can_man_settings'
WHERE `id` = " . intval($row['id']));
}
}
}
function down($hesk_settings) {
$this->executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users`
SET `can_manage_settings` = '0'
WHERE `heskprivileges` NOT LIKE '%can_man_settings%'");
}
}

@ -0,0 +1,15 @@
<?php
namespace v230;
class DropCanChangeNotificationSettingsColumn extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` DROP COLUMN `can_change_notification_settings`");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` ADD COLUMN `can_change_notification_settings` ENUM('0', '1') NOT NULL DEFAULT '1'");
}
}

@ -0,0 +1,15 @@
<?php
namespace v230;
class DropCanManSettingsColumn extends \AbstractMigration {
function up($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` DROP COLUMN `can_manage_settings`");
}
function down($hesk_settings) {
$this->executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` ADD COLUMN `can_manage_settings` ENUM ('0', '1') NOT NULL DEFAULT '1'");
}
}
Loading…
Cancel
Save