-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinstall.php
More file actions
185 lines (178 loc) · 4.87 KB
/
install.php
File metadata and controls
185 lines (178 loc) · 4.87 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/*
** HELPERS
*/
function databaseTableExists($db, $tableName){
$tableCheck = $db->query(
<<<SQL
SHOW TABLES LIKE '{$db->prefix}{$tableName}'
SQL
);
if ($tableCheck->rowCount() > 0) {
return true;
}
return false;
}
/*
** ARRAY: ITEM TYPE
*/
function curatescapeStoryItemType(){
return array(
'name'=> 'Curatescape Story',
'description' => 'A narrative body of text in article format, typically describing a physical location.',
);
}
/*
** ARRAY: ELEMENTS
*/
function curatescapeStoryElements(){
return array(
array(
'name'=>'Subtitle',
'description'=>'A subtitle or alternate title for the entry.',
'order'=>1,
),
array(
'name'=>'Lede',
'description'=>'A brief introductory text that is intended to entice the reader to read the full entry.',
'order'=>2,
),
array(
'name'=>'Story',
'description'=>'The primary full-text for the entry.',
'order'=>3,
),
array(
'name'=>'Sponsor',
'description'=>'The name of a person or organization that has sponsored the research for this specific entry.',
'order'=>4,
),
array(
'name'=>'Factoid',
'description'=>'One or more facts or pieces of information related to the entry, often presented as a list. Examples include architectural metadata, preservation status, FAQs, pieces of trivia, etc.',
'order'=>5,
),
array(
'name'=>'Related Resources',
'description'=>'The name of or link to a related resource, often used for citation information.',
'order'=>6,
),
array(
'name'=>'Official Website',
'description'=>'An official website related to the entry.',
'order'=>7,
),
array(
'name'=>'Street Address',
'description'=>'A single-line street or mailing address for a physical location.',
'order'=>8,
),
array(
'name'=>'Access Information',
'description'=>'Information regarding physical access to a location, including restrictions, onsite directions, or other useful details (e.g. "Private Property," Location is approximate," "Demolished," etc.).',
'order'=>9,
),
);
}
/*
** INSTALL PLUGIN OPTIONS
*/
$this->_installOptions();
/*
** INSTALL ITEM TYPE AND ELEMENTS
*/
$itemTypeMeta = curatescapeStoryItemType();
$elements = curatescapeStoryElements();
$newElements=array();
foreach(curatescapeStoryElements() as $element){
if(!element_exists('Item Type Metadata',$element['name'])){
$newElements[]=$element;
}else{
$ElementObj=get_record('Element',array(
'elementSet'=>'Item Type Metadata',
'name'=>$element['name']));
$newElements[]=$ElementObj;
}
}
$itemType=get_record('ItemType',array('name'=>$itemTypeMeta['name']));
if(!$itemType){
insert_item_type($itemTypeMeta, $newElements);
}else{
$itemType->addElements($newElements);
$itemType->save();
}
/*
** CREATE/MIGRATE DATABASE TABLES
*/
$db = $this->_db;
// CREATE curatescape_tours table
$db->query(
<<<SQL
CREATE TABLE IF NOT EXISTS `{$db->CuratescapeTour}` (
`id` int( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` varchar( 255 ) DEFAULT NULL,
`description` text NOT NULL,
`credits` text,
`postscript_text` text,
`featured` tinyint( 1 ) DEFAULT '0',
`public` tinyint( 1 ) DEFAULT '0',
`ordinal` INT NOT NULL DEFAULT '0',
`added` TIMESTAMP NOT NULL DEFAULT '2000-01-01 00:00:00',
`modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY( `id` )
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
SQL
);
// CREATE curatescape_tour_items table
$db->query(
<<<SQL
CREATE TABLE IF NOT EXISTS `{$db->CuratescapeTourItem}` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
`tour_id` INT( 10 ) UNSIGNED NOT NULL,
`ordinal` INT NOT NULL,
`item_id` INT( 10 ) UNSIGNED NOT NULL,
`subtitle` text DEFAULT NULL,
`text` text DEFAULT NULL,
PRIMARY KEY( `id` ),
KEY `curatescape_tours` ( `tour_id` )
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
SQL
);
// UPDATE existing tour tags from legacy TourBuilder plugin
$db->query(
<<<SQL
UPDATE `{$db->RecordsTags}`
SET `record_type` = 'CuratescapeTour'
WHERE `record_type` = 'Tour';
SQL
);
// COPY existing tours from legacy TourBuilder plugin
if (databaseTableExists($db,'tours')) {
$db->query(
<<<SQL
INSERT INTO `{$db->CuratescapeTour}` (id,title,description,credits,postscript_text,featured,public,ordinal,added,modified)
SELECT id,title,description,credits,postscript_text,featured,public,ordinal,NOW(),NOW()
FROM `{$db->prefix}tours` as t
WHERE NOT EXISTS (
SELECT 1
FROM `{$db->CuratescapeTour}` AS ct
WHERE t.id = ct.id
);
SQL
);
}
// COPY existing tour items from legacy TourBuilder plugin
if(databaseTableExists($db,'tour_items')){
$db->query(
<<<SQL
INSERT INTO `{$db->CuratescapeTourItem}` (id,tour_id,ordinal,item_id,subtitle,text)
SELECT id,tour_id,ordinal,item_id,subtitle,text
FROM `{$db->prefix}tour_items` as ti
WHERE NOT EXISTS (
SELECT 1
FROM `{$db->CuratescapeTourItem}` AS cti
WHERE ti.id = cti.id
);
SQL
);
}