forked from shakty/Patterns
-
Notifications
You must be signed in to change notification settings - Fork 3
/
patterns.install
231 lines (214 loc) · 6.88 KB
/
patterns.install
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
/**
* @file
* Installation file for Patterns.
*/
module_load_include('inc', 'patterns', 'includes/variables');
module_load_include('inc', 'patterns', 'includes/config');
module_load_include('inc', 'patterns', 'includes/path');
module_load_include('inc', 'patterns', 'includes/io/io');
module_load_include('inc', 'patterns', 'includes/utils');
/**
* Implements hook_install().
*/
function patterns_install() {
variable_set('patterns_engine_state', 'on');
variable_set('patterns_public_url', 'patterns');
}
/**
* Implements hook_uninstall().
*/
function patterns_uninstall() {
$del = db_delete('variable')
->condition('name', 'patterns_%', 'LIKE')
->execute();
}
/**
* Implements hook_schema().
*/
function patterns_schema() {
$schema['patterns'] = array(
'description' => 'Stores patterns information.',
'fields' => array(
'pid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Primary Key: Unique pattern ID.',
),
'name' => array(
'type' => 'varchar',
'length' => 55,
'default' => '',
'description' => 'Machine readable name of this pattern.',
),
'format' => array(
'type' => 'varchar',
'length' => 10,
'default' => '',
'description' => 'Format of the patterns (XML, YAML, etc.).',
),
/*
* STATUSES:
*
* 0: installed, not enabled
* 1: installed, enabled
*
* -1: invalid
* -5: removed
*/
'status' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
'description' => 'Boolean indicating whether the pattern has been executed (enabled).',
),
'public' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Boolean indicating whether the pattern is published (available for sharing via patterns server).',
),
'file' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Path of the pattern file relative to Drupal root.',
),
'updated' => array(
'type' => 'varchar',
'length' => 10,
'not null' => TRUE,
'default' => '0',
'description' => 'The Unix timestamp indicating when the pattern file was last time updated (modified).',
),
'enabled' => array(
'type' => 'varchar',
'length' => 10,
'not null' => TRUE,
'default' => '0',
'description' => 'The Unix timestamp indicating when the pattern was last time executed.',
),
'title' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Title of the pattern.',
),
'description' => array(
'type' => 'text',
'not null' => TRUE,
'description' => 'Description of the pattern.',
),
'pattern' => array(
'type' => 'text',
'size' => 'medium',
'not null' => TRUE,
'description' => 'A serialized array containing pattern code.',
),
'uuuid' => array(
'type' => 'varchar',
'length' => 50,
'default' => '',
'description' => 'Identify patterns and their parent',
),
'author' => array(
'type' => 'varchar',
'length' => 20,
'default' => '',
'description' => 'pattern\'s author',
),
),
'primary key' => array('pid'),
'unique keys' => array('name' => array('name'))
);
return $schema;
}
/**
* Add uuuid and author field to {patterns} table.
*/
function patterns_update_7200() {
// Add the uuuid field to the db.
if (!db_field_exists('patterns', 'uuuid')) {
$uuuid = array(
'type' => 'varchar',
'length' => 50,
'default' => '',
'description' => 'Identify patterns and their parent',
);
db_add_field('patterns', 'uuuid', $uuuid);
}
// Add the author field to the db.
if (!db_field_exists('patterns', 'author')) {
$author = array(
'type' => 'varchar',
'length' => 20,
'default' => '',
'description' => 'pattern\'s author',
);
db_add_field('patterns', 'author', $author);
}
}
/**
* Implements hook_requirements().
*
* @param string $phase The phase in which hook_requirements is run (install|runtime).
*/
function patterns_requirements($phase) {
$requirements = array();
// Checking if patterns directory is writable
// Must be done at installation and runtime
// patterns_path_get_files_dir() returns NULL;
$dir = variable_get('patterns_save_file', PATTERNS_FILES_DIR_DEFAULT);
if (!_patterns_io_is_patterns_dir_ready($dir, FILE_CREATE_DIRECTORY)) {
$requirements['pdir'] = array(
'title' => t('Patterns files dir writable'),
'description' => t('Patterns folder does not exist or is not writable: !path',
array('!path' => $dir)),
'severity' => REQUIREMENT_WARNING,
'value' => t('Not writable'),
);
}
else {
$requirements['pdir'] = array(
'title' => t('Patterns files dir'),
'severity' => REQUIREMENT_OK,
'value' => t('Writable'),
);
}
switch ($phase) {
case 'runtime':
if (!ini_get('allow_url_fopen')) {
$requirements['allow_url_fopen'] = array(
'title' => t('Patterns import files from remote URL'),
'description' => t('To import patterns directly from remote URL \'allow_url_fopen\' must be enabled in your PHP configuration.'),
'severity' => REQUIREMENT_WARNING,
'value' => t('Disabled'),
);
}
//Trying to detect CodeMirror library.
$library = libraries_detect('codemirror');
if (empty($library['installed'])) {
$requirements['codemirror'] = array(
'title' => t('CodeMirror (JavaScript based code editor)'),
'description' => t('Patterns editor can be better visualized with CodeMirror. To enable CodeMirror support, download the !codemirror and copy it into the libraries folder (e.g. sites/all/libraries/codemirror/). Error: !error',
array('!codemirror' => l(t('library'), 'https://github.com/marijnh/CodeMirror/', array('absolute' => TRUE)), '!error' => $library['error message'])),
'severity' => REQUIREMENT_WARNING,
'value' => t($library['error']),
);
}else{
$requirements['codemirror'] = array(
'title' => t('CodeMirror Library (JavaScript based code editor)'),
'severity' => REQUIREMENT_OK,
'value' => $library['version'],
);
}
break;
}
return $requirements;
}