/
arMigration0162.class.php
92 lines (82 loc) · 2.72 KB
/
arMigration0162.class.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/*
* This file is part of the Access to Memory (AtoM) software.
*
* Access to Memory (AtoM) is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Access to Memory (AtoM) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Access to Memory (AtoM). If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Add taxonomy and terms for user actions
*
* @package AccesstoMemory
* @subpackage migration
*/
class arMigration0162
{
public const VERSION = 162;
public const MIN_MILESTONE = 2;
public function up($configuration)
{
QubitMigrate::bumpTaxonomy(QubitTaxonomy::USER_ACTION_ID, $configuration);
$taxonomy = new QubitTaxonomy();
$taxonomy->id = QubitTaxonomy::USER_ACTION_ID;
$taxonomy->parentId = QubitTaxonomy::ROOT_ID;
$taxonomy->sourceCulture = 'en';
$taxonomy->setName('User actions', ['culture' => 'en']);
$taxonomy->save();
$terms = [
QubitTerm::USER_ACTION_CREATION_ID => 'Creation',
QubitTerm::USER_ACTION_MODIFICATION_ID => 'Modification',
];
foreach ($terms as $id => $name) {
QubitMigrate::bumpTerm($id, $configuration);
$term = new QubitTerm();
$term->id = $id;
$term->parentId = QubitTerm::ROOT_ID;
$term->taxonomyId = QubitTaxonomy::USER_ACTION_ID;
$term->sourceCulture = 'en';
$term->setName($name, ['culture' => 'en']);
$term->save();
}
// Add table audit_log
$sql = <<<'sql'
CREATE TABLE `audit_log`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`object_id` INTEGER NOT NULL,
`user_id` INTEGER,
`user_name` VARCHAR(255),
`action_type_id` INTEGER,
`created_at` DATETIME,
PRIMARY KEY (`id`),
KEY `audit_log_FI_1`(`object_id`),
CONSTRAINT `audit_log_FK_1`
FOREIGN KEY (`object_id`)
REFERENCES `object` (`id`)
ON DELETE CASCADE,
INDEX `audit_log_FI_2` (`user_id`),
CONSTRAINT `audit_log_FK_2`
FOREIGN KEY (`user_id`)
REFERENCES `user` (`id`)
ON DELETE SET NULL,
INDEX `audit_log_FI_3` (`action_type_id`),
CONSTRAINT `audit_log_FK_3`
FOREIGN KEY (`action_type_id`)
REFERENCES `term` (`id`)
ON DELETE SET NULL
)Engine=InnoDB;
sql;
QubitPdo::modify($sql);
return true;
}
}