-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmetatag.install
278 lines (258 loc) · 11.5 KB
/
metatag.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?php
/**
* @file
* Install, update, and uninstall functions for the metatag module.
*/
use Drupal\Core\Database\Database;
/**
* Implements hook_requirements().
*/
function metatag_requirements($phase) {
$requirements = array();
// Ensure translations don't break during installation.
if ($phase == 'install') {
// Handle scenarios where the site had the legacy "metatags" module
// installed but then had Metatag installed on top of it.
if (function_exists('db_table_exists') && function_exists('db_field_exists') && function_exists('db_query') && Database::isActiveConnection()) {
// Check if the primary table already exists.
if (db_table_exists('metatag')) {
// Check to see if all of the fields exist in the table. If one of the
// fields does not exist, proceed with the fix.
$fields = array(
'entity_type',
'entity_id',
'revision_id',
'language',
'data',
);
foreach ($fields as $field) {
// This field doesn't exist, so determine what to do.
if (!db_field_exists('metatag', $field)) {
// The table contains data, so rename it.
if (db_query("SELECT COUNT(*) FROM {metatag}")->fetchField() > 0) {
db_query("RENAME TABLE {metatag} TO {metatag}_legacy");
$message = 'An out-of-date version of the {metatag} table was discovered. As the table contained data it was renamed with a suffix of "_legacy". This will not prevent installation from continuing, but will need to be dealt with later. See <a href="https://www.drupal.org/node/1391554">https://www.drupal.org/node/1391554</a> for further details.';
}
// The table is empty, so delete it.
else {
db_query("DROP TABLE {metatag}");
$message = 'An out-of-date version of the {metatag} table was discovered. As the table was empty it was simply removed so that it could be recreated in the correct format. Installation may now proceed. See <a href="https://www.drupal.org/node/1391554">https://www.drupal.org/node/1391554</a> for further details.';
}
$requirements['metatag'] = array(
'severity' => REQUIREMENT_WARNING,
'title' => 'Metatag',
'value' => t('Legacy data discovered.'),
'description' => t($message),
);
drupal_set_message(t($message), 'warning');
break;
}
}
}
}
}
elseif ($phase == 'runtime') {
// Work out the release of D7 that is currently running.
list($major, $minor) = explode('.', Drupal::VERSION);
// Strip off any suffixes on the version string, e.g. "17-dev".
if (strpos('-', $minor)) {
list($minor, $suffix) = explode('-', $minor);
}
// Releases of Drupal older than 7.28 did not have entity_language(), which
// is now required, and had a broken [node:summary] token.
if ($minor < 28) {
$requirements['metatag'] = array(
'severity' => REQUIREMENT_WARNING,
'title' => 'Metatag',
'value' => t('Upgrade Drupal core to v7.28 or newer'),
'description' => t("This older version of Drupal core is missing functionality necessary for the module's multilingual support and contains a broken [node:summary] token, it must be upgraded to version 7.28 or newer."),
);
}
// Everything's OK.
else {
$requirements['metatag'] = array(
'severity' => REQUIREMENT_OK,
'title' => 'Metatag',
'value' => t('Drupal core is compatible'),
'description' => t('Older versions of Drupal core contained bugs that made them incompatible with Metatag, but this version will work correctly.'),
);
}
// Add a note if Page Title is also installed.
if (\Drupal::moduleHandler()->moduleExists('page_title')) {
$requirements['metatag_page_title'] = array(
'severity' => REQUIREMENT_INFO,
'title' => 'Metatag',
'value' => t('Possible conflicts with Page Title module'),
'description' => t('The Metatag module is able to customize page titles so running the Page Title module simultaneously can lead to complications.'),
);
}
// Add a note if the deprecated metatag.entity_translation.inc file still
// exists.
$filename = 'metatag.entity_translation.inc';
if (file_exists(dirname(__FILE__) . '/' . $filename)) {
$requirements['metatag_deprecated_et_file'] = array(
'severity' => REQUIREMENT_ERROR,
'title' => 'Metatag',
'value' => t('Unwanted :filename file found', array(':filename' => $filename)),
'description' => t("The :filename file was removed in v7.x-1.0-beta5 but it still exists in the site's Metatag module's directory and will cause problems. This file needs to be removed. The file's path in the Drupal directory structure is:<br /><code>!short_path</code><br />The file's full path is:<br /><code>!full_path</code>", array(':filename' => $filename, '!short_path' => drupal_get_path('module', 'metatag') . '/' . $filename, '!full_path' => dirname(__FILE__) . $filename)),
);
}
// Check that Entity_Translation is current.
if (\Drupal::moduleHandler()->moduleExists('entity_translation')) {
$rev = db_query("SELECT schema_version FROM {system} WHERE name = :module", array(':module' => 'entity_translation'))->fetchColumn();
if ($rev < 7004) {
$requirements['metatag_et_old'] = array(
'severity' => REQUIREMENT_ERROR,
'title' => 'Metatag',
'value' => t('<a href="@url">Entity_Translation</a> is out of date and requires updating', array('@url' => 'http://drupal.org/project/entity_translation')),
'description' => t('The Entity_Translation module is out of date and needs to be updated in order to be compatible with Metatag.'),
);
}
}
// It's recommended to install the Transliteration module to clean up file
// paths for use with image meta tags.
if (!\Drupal::moduleHandler()->moduleExists('transliteration')) {
$requirements['metatag_transliteration'] = array(
'severity' => REQUIREMENT_INFO,
'title' => 'Metatag',
'value' => t('The Transliteration module is recommended.'),
'description' => t("It is recommended to install the <a href=\"@url\">Transliteration module</a> to clean up filenames of uploaded files that may be used with image meta tags.", array('@url' => 'https://drupal.org/project/transliteration')),
);
}
// It's recommended to install the Imagecache Token module to make image
// tokens easier to do.
if (!\Drupal::moduleHandler()->moduleExists('imagecache_token')) {
$requirements['metatag_imagecache_token'] = array(
'severity' => REQUIREMENT_INFO,
'title' => 'Metatag',
'value' => t('The Imagecache Token module is recommended.'),
'description' => t("It is recommended to install the <a href=\"@url\">Imagecache Token module</a> to make it easier to control image meta tags, e.g. og:image.", array('@url' => 'https://drupal.org/project/imagecache_token')),
);
}
// The Admin Language module can cause problems.
if (!\Drupal::moduleHandler()->moduleExists('admin_language') && \Drupal::config('metatag.settings')->get('admin_language_force_neutral')) {
// $requirements['metatag_admin_language'] = array(
// 'severity' => REQUIREMENT_WARNING,
// 'title' => 'Metatag',
// 'value' => t('Conflict with Admin Language module.'),
// 'description' => t("Using the \"@option\" with Metatag can lead to data loss, so it is recommended to <a href=\"@url\">disable that option</a>.", array('@option' => t('Force language neutral aliases'), '@url' => url('admin/config/regional/language/admin_language'))),
// );
}
}
return $requirements;
}
/**
* Implements hook_schema().
*/
function metatag_schema() {
$schema['metatag_config'] = array(
'description' => 'Storage of meta tag configuration and defaults.',
'export' => array(
'key' => 'instance',
'key name' => 'Instance',
'primary key' => 'cid',
'identifier' => 'config',
'default hook' => 'metatag_config_default',
'api' => array(
'owner' => 'metatag',
'api' => 'metatag',
'minimum_version' => 1,
'current_version' => 1,
),
'cache defaults' => TRUE,
'default cache bin' => 'cache_metatag',
),
'fields' => array(
'cid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The primary identifier for a metatag configuration set.',
'no export' => TRUE,
),
'instance' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The machine-name of the configuration, typically entity-type:bundle.',
),
'config' => array(
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE,
'description' => 'Serialized data containing the meta tag configuration.',
'translatable' => TRUE,
),
),
'primary key' => array('cid'),
'unique keys' => array(
'instance' => array('instance'),
),
);
$schema['metatag'] = array(
'fields' => array(
'entity_type' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => 'The entity type this data is attached to.',
),
'entity_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The entity id this data is attached to.',
),
'revision_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The revision_id for the entity object this data is attached to.',
),
'language' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => 'The language of the tag.',
),
'data' => array(
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE,
),
),
'indexes' => array(
'type_revision' => array('entity_type','revision_id'),
),
'primary key' => array('entity_type', 'entity_id', 'revision_id', 'language'),
);
$schema['cache_metatag'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_metatag']['description'] = t('Cache table for the generated meta tag output.');
return $schema;
}
/*
* Implements hook_uninstall().
*/
function metatag_uninstall() {
// This variable is created via hook_enable.
\Drupal::config('metatag.settings')->clear('metatag_schema_installed');
// Used to control whether 403/404 pages are cached.
\Drupal::config('metatag.settings')->clear('metatag_cache_error_pages');
// Used to make meta tags display on admin pages.
\Drupal::config('metatag.settings')->clear('metatag_tag_admin_pages');
// Temp variables, just in case they weren't removed already.
\Drupal::config('metatag.settings')->clear('metatag_skip_update_7017');
// Used to note that the schema for the main {metatag} table were sufficiently
// updated.
\Drupal::config('metatag.settings')->clear('metatag_has_revision_id');
// Used to force an entity's default language values to be used if nothing
// else matched.
\Drupal::config('metatag.settings')->clear('metatag_entity_no_lang_default');
}