|
@@ -54,6 +54,9 @@ function metatag_requirements($phase) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
elseif ($phase == 'runtime') {
|
|
elseif ($phase == 'runtime') {
|
|
|
|
+ // Complete data dump of all installed modules, used later.
|
|
|
|
+ $module_data = system_rebuild_module_data();
|
|
|
|
+
|
|
// Work out the release of D7 that is currently running.
|
|
// Work out the release of D7 that is currently running.
|
|
list($major, $minor) = explode('.', VERSION);
|
|
list($major, $minor) = explode('.', VERSION);
|
|
// Strip off any suffixes on the version string, e.g. "17-dev".
|
|
// Strip off any suffixes on the version string, e.g. "17-dev".
|
|
@@ -71,15 +74,6 @@ function metatag_requirements($phase) {
|
|
'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."),
|
|
'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.
|
|
// Add a note if Page Title is also installed.
|
|
if (module_exists('page_title')) {
|
|
if (module_exists('page_title')) {
|
|
@@ -104,16 +98,16 @@ function metatag_requirements($phase) {
|
|
}
|
|
}
|
|
|
|
|
|
// Check that Entity_Translation is current.
|
|
// Check that Entity_Translation is current.
|
|
- if (module_exists('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.'),
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
|
|
+ if (module_exists('entity_translation')
|
|
|
|
+ && !empty($module_data['entity_translation'])
|
|
|
|
+ && !empty($module_data['entity_translation']->schema_version)
|
|
|
|
+ && $module_data['entity_translation']->schema_version < 7004) {
|
|
|
|
+ $requirements['metatag_et_version'] = array(
|
|
|
|
+ 'severity' => REQUIREMENT_ERROR,
|
|
|
|
+ 'title' => 'Metatag',
|
|
|
|
+ 'value' => $t('<a href="@url">Entity_Translation</a> is out of date and requires updating', array('@url' => 'https://www.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
|
|
// It's recommended to install the Transliteration module to clean up file
|
|
@@ -134,12 +128,12 @@ function metatag_requirements($phase) {
|
|
'severity' => REQUIREMENT_INFO,
|
|
'severity' => REQUIREMENT_INFO,
|
|
'title' => 'Metatag',
|
|
'title' => 'Metatag',
|
|
'value' => $t('The Imagecache Token module is recommended.'),
|
|
'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')),
|
|
|
|
|
|
+ '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. See the Metatag module's README.txt for details.", array('@url' => 'https://drupal.org/project/imagecache_token')),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
// The Admin Language module can cause problems.
|
|
// The Admin Language module can cause problems.
|
|
- if (!module_exists('admin_language') && variable_get('admin_language_force_neutral', 0)) {
|
|
|
|
|
|
+ if (module_exists('admin_language') && variable_get('admin_language_force_neutral', 0)) {
|
|
$requirements['metatag_admin_language'] = array(
|
|
$requirements['metatag_admin_language'] = array(
|
|
'severity' => REQUIREMENT_WARNING,
|
|
'severity' => REQUIREMENT_WARNING,
|
|
'title' => 'Metatag',
|
|
'title' => 'Metatag',
|
|
@@ -147,6 +141,46 @@ function metatag_requirements($phase) {
|
|
'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'))),
|
|
'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'))),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // Token v7.x-1.6 is *highly* recommended.
|
|
|
|
+ $token_module = $module_data['token'];
|
|
|
|
+ // If the version string is not present then it means the module is running
|
|
|
|
+ // from git, which means it can't be compared against. Alternatively, look
|
|
|
|
+ // for the test file, which was the last commit of the 1.6 release.
|
|
|
|
+ if (!empty($token_module->info['version'])
|
|
|
|
+ || empty($token_module->info['files'])) {
|
|
|
|
+ // If there's no test file then this is older than v1.6.
|
|
|
|
+ if (empty($token_module->info['files'])) {
|
|
|
|
+ $minor = 5;
|
|
|
|
+ }
|
|
|
|
+ // Otherwise check the version string.
|
|
|
|
+ else {
|
|
|
|
+ // Versions are in the format 7.x-1.y, so split the string up to find
|
|
|
|
+ // the 'y' portion.
|
|
|
|
+ $version = explode('-', $token_module->info['version']);
|
|
|
|
+ if (isset($version[1])) {
|
|
|
|
+ list($major, $minor) = explode('.', $version[1]);
|
|
|
|
+ // Strip off any suffixes on the version string, e.g. "17-dev".
|
|
|
|
+ if (strpos('-', $minor)) {
|
|
|
|
+ list($minor, $suffix) = explode('-', $minor);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // If the version string couldn't be extracted correctly, assume that
|
|
|
|
+ // an incorrect version is installed.
|
|
|
|
+ else {
|
|
|
|
+ $minor = 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // If v1.6 is not installed, give a warning.
|
|
|
|
+ if ($minor < 6) {
|
|
|
|
+ $requirements['metatag_token_version'] = array(
|
|
|
|
+ 'severity' => REQUIREMENT_WARNING,
|
|
|
|
+ 'title' => 'Metatag',
|
|
|
|
+ 'value' => $t('Token module is out of date.'),
|
|
|
|
+ 'description' => $t('It is highly recommended to install <a href="https://www.drupal.org/project/token">Token module</a> v7.x-1.6 or newer, otherwise there may be problems using certain meta tags.'),
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
return $requirements;
|
|
return $requirements;
|
|
@@ -241,13 +275,21 @@ function metatag_schema() {
|
|
),
|
|
),
|
|
),
|
|
),
|
|
'indexes' => array(
|
|
'indexes' => array(
|
|
- 'type_revision' => array('entity_type','revision_id'),
|
|
|
|
|
|
+ 'type_revision' => array(
|
|
|
|
+ 'entity_type',
|
|
|
|
+ 'revision_id',
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ 'primary key' => array(
|
|
|
|
+ 'entity_type',
|
|
|
|
+ 'entity_id',
|
|
|
|
+ 'revision_id',
|
|
|
|
+ 'language',
|
|
),
|
|
),
|
|
- 'primary key' => array('entity_type', 'entity_id', 'revision_id', 'language'),
|
|
|
|
);
|
|
);
|
|
|
|
|
|
$schema['cache_metatag'] = drupal_get_schema_unprocessed('system', 'cache');
|
|
$schema['cache_metatag'] = drupal_get_schema_unprocessed('system', 'cache');
|
|
- $schema['cache_metatag']['description'] = t('Cache table for the generated meta tag output.');
|
|
|
|
|
|
+ $schema['cache_metatag']['description'] = 'Cache table for the generated meta tag output.';
|
|
|
|
|
|
return $schema;
|
|
return $schema;
|
|
}
|
|
}
|
|
@@ -257,6 +299,86 @@ function metatag_schema() {
|
|
*/
|
|
*/
|
|
function metatag_install() {
|
|
function metatag_install() {
|
|
drupal_set_message(t("Thank you for installing the Metatag module. It is recommended to read the module's <a href=\"!url\" title=\"Read the Metatag module's documentation\">README.txt</a> file as there are some known issues that may affect this site.", array('!url' => url(drupal_get_path('module', 'metatag') . '/README.txt'))));
|
|
drupal_set_message(t("Thank you for installing the Metatag module. It is recommended to read the module's <a href=\"!url\" title=\"Read the Metatag module's documentation\">README.txt</a> file as there are some known issues that may affect this site.", array('!url' => url(drupal_get_path('module', 'metatag') . '/README.txt'))));
|
|
|
|
+
|
|
|
|
+ // Always enable the node, taxonomy term and user entities.
|
|
|
|
+ foreach (array('node', 'taxonomy_term', 'user') as $entity_type) {
|
|
|
|
+ // Enable the main entity type.
|
|
|
|
+ $variable_name = 'metatag_enable_' . $entity_type;
|
|
|
|
+ variable_set($variable_name, TRUE);
|
|
|
|
+
|
|
|
|
+ // Update each entity bundle too.
|
|
|
|
+ $entity_info = entity_get_info($entity_type);
|
|
|
|
+ if (!empty($entity_info['bundles'])) {
|
|
|
|
+ foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
|
|
|
|
+ $variable_name = 'metatag_enable_' . $entity_type . '__' . $bundle_name;
|
|
|
|
+ variable_set($variable_name, TRUE);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Possibly enable other entities, if they're specifically requested.
|
|
|
|
+ foreach (entity_get_info() as $entity_type => $entity_info) {
|
|
|
|
+ // Skip the three entity types that were already enabled.
|
|
|
|
+ if (in_array($entity_type, array('node', 'taxonomy_term', 'user'))) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $variable_name = 'metatag_enable_' . $entity_type;
|
|
|
|
+
|
|
|
|
+ // Configuration entities are skipped.
|
|
|
|
+ if (isset($entity_info['configuration']) && $entity_info['configuration'] == TRUE) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Entities must have bundles.
|
|
|
|
+ if (empty($entity_info['bundles'])) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Entities must be fieldable.
|
|
|
|
+ elseif (empty($entity_info['fieldable'])) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Ignore some view modes that are automatically added by certain modules.
|
|
|
|
+ unset($entity_info['view modes']['ical']);
|
|
|
|
+ unset($entity_info['view modes']['diff_standard']);
|
|
|
|
+ unset($entity_info['view modes']['token']);
|
|
|
|
+
|
|
|
|
+ // Entities without view modes are skipped.
|
|
|
|
+ if (empty($entity_info['view modes'])) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // At this point, disable the entity by default.
|
|
|
|
+ $entity_enabled = FALSE;
|
|
|
|
+
|
|
|
|
+ // Anything that was specifically enabled via hook_entity_info() from older
|
|
|
|
+ // versions will be enabled if not configured already.
|
|
|
|
+ if (!empty($entity_info['metatag']) || !empty($entity_info['metatags'])) {
|
|
|
|
+ $entity_enabled = variable_get($variable_name, 'monkey');
|
|
|
|
+ if ($entity_enabled === 'monkey') {
|
|
|
|
+ $entity_enabled = TRUE;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ variable_set($variable_name, $entity_enabled);
|
|
|
|
+
|
|
|
|
+ // Loop through the bundles, but only if the entity is enabled.
|
|
|
|
+ if ($entity_enabled) {
|
|
|
|
+ foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
|
|
|
|
+ $variable_name = 'metatag_enable_' . $entity_type . '__' . $bundle_name;
|
|
|
|
+
|
|
|
|
+ // If it wasn't specifically disabled before, enable it.
|
|
|
|
+ $bundle_enabled = variable_get($variable_name, 'monkey');
|
|
|
|
+ if ($bundle_name != FALSE) {
|
|
|
|
+ variable_set($variable_name, TRUE);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ drupal_set_message(t('It may be worth verifying on the <a href="@url">Settings page</a> which types of content on the site should allow meta tags.', array('@url' => url('admin/config/search/metatags/settings'))));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -280,6 +402,49 @@ function metatag_uninstall() {
|
|
// Used to force an entity's default language values to be used if nothing
|
|
// Used to force an entity's default language values to be used if nothing
|
|
// else matched.
|
|
// else matched.
|
|
variable_del('metatag_entity_no_lang_default');
|
|
variable_del('metatag_entity_no_lang_default');
|
|
|
|
+
|
|
|
|
+ // Controls which page region is used to trigger output of the meta tags.
|
|
|
|
+ variable_del('metatag_page_region');
|
|
|
|
+
|
|
|
|
+ // Optionally disable the default configurations.
|
|
|
|
+ variable_del('metatag_load_defaults');
|
|
|
|
+
|
|
|
|
+ // Optionally disables the output cache.
|
|
|
|
+ variable_del('metatag_cache_output');
|
|
|
|
+
|
|
|
|
+ // Customizable pager string.
|
|
|
|
+ variable_del('metatag_pager_string');
|
|
|
|
+
|
|
|
|
+ // Optionally enable translations of final output.
|
|
|
|
+ variable_del('metatag_i18n_translate_output');
|
|
|
|
+
|
|
|
|
+ // Optionally enable the automatic watchdog logging of i18n strings.
|
|
|
|
+ variable_del('metatag_i18n_enable_watchdog');
|
|
|
|
+
|
|
|
|
+ // Optionally disable the i18n integration.
|
|
|
|
+ variable_del('metatag_i18n_disabled');
|
|
|
|
+
|
|
|
|
+ // Optionally output core's meta tags.
|
|
|
|
+ variable_del('metatag_leave_core_tags');
|
|
|
|
+
|
|
|
|
+ // Optionally enable individual permissions for each meta tag.
|
|
|
|
+ variable_del('metatag_extended_permissions');
|
|
|
|
+
|
|
|
|
+ // Optionally load meta tags on admin pages.
|
|
|
|
+ variable_del('metatag_load_all_pages');
|
|
|
|
+
|
|
|
|
+ // Sanitize token replacement output.
|
|
|
|
+ variable_del('metatag_token_sanitize');
|
|
|
|
+
|
|
|
|
+ // Remove all possible 'enable' variables.
|
|
|
|
+ foreach (entity_get_info() as $entity_type => $entity_info) {
|
|
|
|
+ variable_del('metatag_enable_' . $entity_type);
|
|
|
|
+ if (!empty($entity_info['bundles'])) {
|
|
|
|
+ foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
|
|
|
|
+ variable_del('metatag_enable_' . $entity_type . '__' . $bundle_name);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -290,13 +455,119 @@ function metatag_enable() {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Implements hook_disable().
|
|
|
|
|
|
+ * Replace one meta tag with another in the entity records.
|
|
|
|
+ *
|
|
|
|
+ * @param array $sandbox
|
|
|
|
+ * A Batch API sandbox, passed by reference.
|
|
|
|
+ * @param string $old_tag
|
|
|
|
+ * The meta tag that is to be replaced.
|
|
|
|
+ * @param string $new_tag
|
|
|
|
+ * The meta tag that replaces the old one.
|
|
*/
|
|
*/
|
|
-// function metatag_disable() {
|
|
|
|
-// }
|
|
|
|
|
|
+function metatag_update_replace_meta_tag(&$sandbox, $old_tag, $new_tag) {
|
|
|
|
+ if (!isset($sandbox['progress'])) {
|
|
|
|
+ // Count of all {metatag} records that contained an entry for the old meta
|
|
|
|
+ // tag.
|
|
|
|
+ $records_count = db_select('metatag', 'm')
|
|
|
|
+ ->condition('m.data', '%' . db_like('"" . $old_tag . ""') . '%', 'LIKE')
|
|
|
|
+ ->countQuery()
|
|
|
|
+ ->execute()
|
|
|
|
+ ->fetchField();
|
|
|
|
+
|
|
|
|
+ if (empty($records_count)) {
|
|
|
|
+ return t('No Metatag entity records needed to have the "' . $old_tag . '" meta tag renamed.');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $sandbox['max'] = $records_count;
|
|
|
|
+ $sandbox['progress'] = 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Count of rows that will be processed per iteration.
|
|
|
|
+ $limit = 100;
|
|
|
|
+
|
|
|
|
+ // Fetches a part of records.
|
|
|
|
+ $records = db_select('metatag', 'm')
|
|
|
|
+ ->fields('m', array())
|
|
|
|
+ ->condition('m.data', '%' . db_like('"' . $old_tag . '"') . '%', 'LIKE')
|
|
|
|
+ ->range(0, $limit)
|
|
|
|
+ ->execute();
|
|
|
|
+
|
|
|
|
+ $count = 0;
|
|
|
|
+ $keys = array('entity_type', 'entity_id', 'revision_id', 'language');
|
|
|
|
+
|
|
|
|
+ // Loop over the values and correct them.
|
|
|
|
+ foreach ($records as $record) {
|
|
|
|
+ $record->data = unserialize($record->data);
|
|
|
|
+
|
|
|
|
+ if (isset($record->data[$old_tag])) {
|
|
|
|
+ $record->data[$new_tag] = $record->data[$old_tag];
|
|
|
|
+ unset($record->data[$old_tag]);
|
|
|
|
+ drupal_write_record('metatag', $record, $keys);
|
|
|
|
+
|
|
|
|
+ // Clear the cache for the entity this belongs to.
|
|
|
|
+ entity_get_controller($record->entity_type)->resetCache(array($record->entity_id));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $count++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!empty($count)) {
|
|
|
|
+ $sandbox['progress'] += $count;
|
|
|
|
+ $sandbox['#finished'] = min(0.99, $sandbox['progress'] / $sandbox['max']);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $sandbox['#finished'] = 1;
|
|
|
|
+ return t('Converted the "' . $old_tag . '" meta tag for @count entity records to "' . $new_tag . '" meta tag.', array('@count' => $sandbox['progress']));
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Disable the deprecated metatag_ui module which has been merged into metatag.
|
|
|
|
|
|
+ * Replace one meta tag with another in the configs.
|
|
|
|
+ *
|
|
|
|
+ * @param string $old_tag
|
|
|
|
+ * The meta tag that is to be replaced.
|
|
|
|
+ * @param string $new_tag
|
|
|
|
+ * The meta tag that replaces the old one.
|
|
|
|
+ */
|
|
|
|
+function metatag_update_replace_config($old_tag, $new_tag) {
|
|
|
|
+ // Find all {metatag_config} records that contained an entry for the old meta
|
|
|
|
+ // tag.
|
|
|
|
+ $records = db_select('metatag_config', 'm')
|
|
|
|
+ ->fields('m', array('cid', 'config'))
|
|
|
|
+ ->condition('m.config', '%' . db_like('"' . $old_tag . '"') . '%', 'LIKE')
|
|
|
|
+ ->execute();
|
|
|
|
+ // This message will be returned if nothing needed to be updated.
|
|
|
|
+ $none_message = t('No Metatag configuration records needed to have the "og:video" meta tag fixed. That said, there may be other configurations elsewhere that do need updating.');
|
|
|
|
+
|
|
|
|
+ // Loop over the values and correct them.
|
|
|
|
+ if ($records->rowCount() == 0) {
|
|
|
|
+ drupal_set_message($none_message);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $keys = array('cid');
|
|
|
|
+
|
|
|
|
+ // Loop over the values and correct them.
|
|
|
|
+ $counter = 0;
|
|
|
|
+ foreach ($records as $record) {
|
|
|
|
+ $record->config = unserialize($record->config);
|
|
|
|
+ if (isset($record->config[$old_tag])) {
|
|
|
|
+ $record->config[$new_tag] = $record->config[$old_tag];
|
|
|
|
+ unset($record->config['og:video']);
|
|
|
|
+ drupal_write_record('metatag_config', $record, $keys);
|
|
|
|
+ $counter++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if ($counter == 0) {
|
|
|
|
+ drupal_set_message($none_message);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ drupal_set_message(t('Converted the "' . $old_tag . '" meta tag for @count configurations to the new "' . $new_tag . '" meta tag.', array('@count' => $counter)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Disable the deprecated metatag_ui module, which has been merged into metatag.
|
|
*/
|
|
*/
|
|
function metatag_update_7000() {
|
|
function metatag_update_7000() {
|
|
if (module_exists('metatag_ui')) {
|
|
if (module_exists('metatag_ui')) {
|
|
@@ -658,7 +929,7 @@ function metatag_update_7011(&$sandbox) {
|
|
|
|
|
|
// hook_update_N() may optionally return a string which will be displayed
|
|
// hook_update_N() may optionally return a string which will be displayed
|
|
// to the user.
|
|
// to the user.
|
|
- return t('Fixed the Metatag language values for @count nodes.', array('!count' => $sandbox['progress']));
|
|
|
|
|
|
+ return t('Fixed the Metatag language values for @count nodes.', array('@count' => $sandbox['progress']));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1166,6 +1437,13 @@ function metatag_update_7018(&$sandbox) {
|
|
}
|
|
}
|
|
$records = entity_load($entity_type, array($entity_id), $conditions);
|
|
$records = entity_load($entity_type, array($entity_id), $conditions);
|
|
|
|
|
|
|
|
+ // Try to fallback to default language if no record was found. This may
|
|
|
|
+ // happen when using entity_translation as the parent entity table only
|
|
|
|
+ // contains one record.
|
|
|
|
+ if (!empty($conditions) && empty($records)) {
|
|
|
|
+ $records = entity_load($entity_type, array($entity_id));
|
|
|
|
+ }
|
|
|
|
+
|
|
// Fix this record.
|
|
// Fix this record.
|
|
if (!empty($records)) {
|
|
if (!empty($records)) {
|
|
$entity = reset($records);
|
|
$entity = reset($records);
|
|
@@ -1348,40 +1626,10 @@ function metatag_update_7023() {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Rename the 'twitter:image' meta tag to 'twitter:image:src', part 1.
|
|
|
|
|
|
+ * No-op update. Renaming twitter:image to twitter:image:src no longer needed.
|
|
*/
|
|
*/
|
|
function metatag_update_7024() {
|
|
function metatag_update_7024() {
|
|
- // Find all {metatag} records that contained an entry for the old meta tag.
|
|
|
|
- $records = db_query("SELECT entity_type, entity_id, revision_id, language, data
|
|
|
|
- FROM {metatag}
|
|
|
|
- WHERE data LIKE '%twitter:image%'");
|
|
|
|
- // This message will be returned if nothing needed to be updated.
|
|
|
|
- $none_message = t('No Metatag entity records needed to have the "twitter:image" meta tag fixed.');
|
|
|
|
-
|
|
|
|
- if ($records->rowCount() == 0) {
|
|
|
|
- drupal_set_message($none_message);
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- $keys = array('entity_type', 'entity_id', 'revision_id', 'language');
|
|
|
|
-
|
|
|
|
- // Loop over the values and correct them.
|
|
|
|
- $counter = 0;
|
|
|
|
- foreach ($records as $record) {
|
|
|
|
- $record->data = unserialize($record->data);
|
|
|
|
- if (isset($record->data['twitter:image'])) {
|
|
|
|
- $record->data['twitter:image:src'] = $record->data['twitter:image'];
|
|
|
|
- unset($record->data['twitter:image']);
|
|
|
|
- drupal_write_record('metatag', $record, $keys);
|
|
|
|
- $counter++;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if ($counter == 0) {
|
|
|
|
- drupal_set_message($none_message);
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- drupal_set_message(t('Converted the "twitter:image" meta tag for @count entity records to the correct "twitter:image:src" meta tag.', array('@count' => $counter)));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ // Do nothing.
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1394,38 +1642,10 @@ function metatag_update_7025() {
|
|
/**
|
|
/**
|
|
* Rename the 'copyright' meta tag to 'rights', part 1.
|
|
* Rename the 'copyright' meta tag to 'rights', part 1.
|
|
*/
|
|
*/
|
|
-function metatag_update_7026() {
|
|
|
|
- // Find all {metatag} records that contained an entry for the old meta tag.
|
|
|
|
- $records = db_query("SELECT entity_type, entity_id, revision_id, language, data
|
|
|
|
- FROM {metatag}
|
|
|
|
- WHERE data LIKE '%copyright%'");
|
|
|
|
- // This message will be returned if nothing needed to be updated.
|
|
|
|
- $none_message = t('No Metatag entity records needed to have the "copyright" meta tag fixed.');
|
|
|
|
-
|
|
|
|
- if ($records->rowCount() == 0) {
|
|
|
|
- drupal_set_message($none_message);
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- $keys = array('entity_type', 'entity_id', 'revision_id', 'language');
|
|
|
|
-
|
|
|
|
- // Loop over the values and correct them.
|
|
|
|
- $counter = 0;
|
|
|
|
- foreach ($records as $record) {
|
|
|
|
- $record->data = unserialize($record->data);
|
|
|
|
- if (isset($record->data['copyright'])) {
|
|
|
|
- $record->data['rights'] = $record->data['copyright'];
|
|
|
|
- unset($record->data['copyright']);
|
|
|
|
- drupal_write_record('metatag', $record, $keys);
|
|
|
|
- $counter++;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if ($counter == 0) {
|
|
|
|
- drupal_set_message($none_message);
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- drupal_set_message(t('Converted the "copyright" meta tag for @count entity records to the correct "rights" meta tag.', array('@count' => $counter)));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+function metatag_update_7026(&$sandbox) {
|
|
|
|
+ $old_tag = 'copyright';
|
|
|
|
+ $new_tag = 'rights';
|
|
|
|
+ return metatag_update_replace_meta_tag($sandbox, $old_tag, $new_tag);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1436,7 +1656,7 @@ function metatag_update_7027() {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Clear the menu cache so the new Advanced Settings page will be picked up.
|
|
|
|
|
|
+ * Clear the menu cache so the new Settings page will be picked up.
|
|
*/
|
|
*/
|
|
function metatag_update_7028() {
|
|
function metatag_update_7028() {
|
|
variable_set('menu_rebuild_needed', TRUE);
|
|
variable_set('menu_rebuild_needed', TRUE);
|
|
@@ -1446,106 +1666,561 @@ function metatag_update_7028() {
|
|
* Add an index to the {metatag} table to speed up some queries.
|
|
* Add an index to the {metatag} table to speed up some queries.
|
|
*/
|
|
*/
|
|
function metatag_update_7029() {
|
|
function metatag_update_7029() {
|
|
- db_add_index('metatag', 'type_revision', array('entity_type', 'revision_id'));
|
|
|
|
- drupal_set_message(t('Added an index to the main Metatag table that will hopefully improve performance a little.'));
|
|
|
|
|
|
+ if (!db_index_exists('metatag', 'type_revision')) {
|
|
|
|
+ db_add_index('metatag', 'type_revision', array('entity_type', 'revision_id'));
|
|
|
|
+ return t('Added an index to the main Metatag table that will hopefully improve performance a little.');
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return t('Did not add the index, it already existed.');
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Rename the 'twitter:image' meta tag to 'twitter:image:src', part 2.
|
|
|
|
|
|
+ * No-op update. Renaming twitter:image to twitter:image:src no longer needed.
|
|
*/
|
|
*/
|
|
function metatag_update_7030() {
|
|
function metatag_update_7030() {
|
|
- // Find all {metatag_config} records that contained an entry for the old meta
|
|
|
|
- // tag.
|
|
|
|
- $records = db_query("SELECT cid, config
|
|
|
|
- FROM {metatag_config}
|
|
|
|
- WHERE config LIKE '%twitter:image%'");
|
|
|
|
- // This message will be returned if nothing needed to be updated.
|
|
|
|
- $none_message = t('No Metatag configuration records needed to have the "twitter:image" meta tag fixed. That said, there may be other configurations elsewhere that do need updating.');
|
|
|
|
|
|
+ // Do nothing.
|
|
|
|
+}
|
|
|
|
|
|
- // Loop over the values and correct them.
|
|
|
|
- if ($records->rowCount() == 0) {
|
|
|
|
- drupal_set_message($none_message);
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- $keys = array('cid');
|
|
|
|
|
|
+/**
|
|
|
|
+ * Rename the 'copyright' meta tag to 'rights', part 2.
|
|
|
|
+ */
|
|
|
|
+function metatag_update_7031() {
|
|
|
|
+ $old_tag = 'copyright';
|
|
|
|
+ $new_tag = 'rights';
|
|
|
|
+ return metatag_update_replace_config($old_tag, $new_tag);
|
|
|
|
+}
|
|
|
|
|
|
- // Loop over the values and correct them.
|
|
|
|
- $counter = 0;
|
|
|
|
- foreach ($records as $record) {
|
|
|
|
- $record->config = unserialize($record->config);
|
|
|
|
- if (isset($record->config['twitter:image'])) {
|
|
|
|
- $record->config['twitter:image:src'] = $record->config['twitter:image'];
|
|
|
|
- unset($record->config['twitter:image']);
|
|
|
|
- drupal_write_record('metatag_config', $record, $keys);
|
|
|
|
- $counter++;
|
|
|
|
- }
|
|
|
|
|
|
+/**
|
|
|
|
+ * Clear the Metatag cache.
|
|
|
|
+ */
|
|
|
|
+function metatag_update_7032() {
|
|
|
|
+ cache_clear_all('*', 'cache_metatag', TRUE);
|
|
|
|
+ return t('All Metatag caches cleared.');
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * These originally removed the 'author' meta tag, but it was subsequently
|
|
|
|
+ * decided that this was not the correct approach, that the meta tag should not
|
|
|
|
+ * be removed after all.
|
|
|
|
+ *
|
|
|
|
+ * @see https://www.drupal.org/node/2330823
|
|
|
|
+ */
|
|
|
|
+function metatag_update_7033() {
|
|
|
|
+}
|
|
|
|
+function metatag_update_7034() {
|
|
|
|
+}
|
|
|
|
+function metatag_update_7035() {
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Update variables to indicate which entities should be supported.
|
|
|
|
+ */
|
|
|
|
+function metatag_update_7036() {
|
|
|
|
+ foreach (entity_get_info() as $entity_type => $entity_info) {
|
|
|
|
+ $variable_name = 'metatag_enable_' . $entity_type;
|
|
|
|
+
|
|
|
|
+ // Configuration entities are skipped.
|
|
|
|
+ if (isset($entity_info['configuration']) && $entity_info['configuration'] == TRUE) {
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
- if ($counter == 0) {
|
|
|
|
- drupal_set_message($none_message);
|
|
|
|
|
|
+
|
|
|
|
+ // Entities without view modes are skipped.
|
|
|
|
+ elseif (empty($entity_info['view modes'])) {
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // Basic core entities or "normal" entities that have been enabled via the
|
|
|
|
+ // API.
|
|
|
|
+ elseif (in_array($entity_type, array('node', 'taxonomy_term', 'user')) ||
|
|
|
|
+ !empty($entity_info['metatag']) || !empty($entity_info['metatags'])) {
|
|
|
|
+ // Check if the entity type has been enabled or disabled previously; if
|
|
|
|
+ // the variable equals a junk value then it was not previously set,
|
|
|
|
+ // therefore we'll set a default.
|
|
|
|
+ if (variable_get($variable_name, 'monkey') == 'monkey') {
|
|
|
|
+ // By default these entity types are enabled.
|
|
|
|
+ variable_set($variable_name, TRUE);
|
|
|
|
+ // Check each entity bundle.
|
|
|
|
+ if (!empty($entity_info['bundles'])) {
|
|
|
|
+ foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
|
|
|
|
+ $variable_name = 'metatag_enable_' . $entity_type . '__' . $bundle_name;
|
|
|
|
+ // Check if the bundle has been enabled or disabled previously; if
|
|
|
|
+ // the variable equals a junk value then it was not previously set,
|
|
|
|
+ // therefore we'll set a default.
|
|
|
|
+ if (variable_get($variable_name, 'monkey') == 'monkey') {
|
|
|
|
+ if (!empty($bundle_info['metatag']) || !empty($bundle_info['metatags'])) {
|
|
|
|
+ variable_set($variable_name, TRUE);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ variable_set($variable_name, FALSE);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // This variable was set before.
|
|
|
|
+ else {
|
|
|
|
+ // Do nothing.
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // This variable was set before.
|
|
|
|
+ else {
|
|
|
|
+ // Do nothing.
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Disable this entity type.
|
|
else {
|
|
else {
|
|
- drupal_set_message(t('Converted the "twitter:image" meta tag for @count configurations to the correct "twitter:image:src" meta tag.', array('@count' => $counter)));
|
|
|
|
|
|
+ variable_set($variable_name, FALSE);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // Clear the caches.
|
|
|
|
+ cache_clear_all('*', 'cache_metatag', TRUE);
|
|
|
|
+ drupal_static_reset('metatag_config_load_with_defaults');
|
|
|
|
+ drupal_static_reset('metatag_entity_supports_metatags');
|
|
|
|
+ ctools_include('export');
|
|
|
|
+ ctools_export_load_object_reset('metatag_config');
|
|
|
|
+
|
|
|
|
+ drupal_set_message(t('The way that Metatag tracks which entity types are compatible has changed. Please review the <a href="@url">Settings page</a> to ensure that all of the entity types are enabled correctly.', array('@url' => 'admin/config/search/metatags/settings')));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Rename the 'copyright' meta tag to 'rights', part 2.
|
|
|
|
|
|
+ * Clear the menu cache so the renamed Settings page will be picked up.
|
|
*/
|
|
*/
|
|
-function metatag_update_7031() {
|
|
|
|
- // Find all {metatag_config} records that contained an entry for the old meta
|
|
|
|
- // tag.
|
|
|
|
- $records = db_query("SELECT cid, config
|
|
|
|
- FROM {metatag_config}
|
|
|
|
- WHERE config LIKE '%copyright%'");
|
|
|
|
- // This message will be returned if nothing needed to be updated.
|
|
|
|
- $none_message = t('No Metatag configuration records needed to have the "copyright" meta tag fixed. That said, there may be other configurations elsewhere that do need updating.');
|
|
|
|
|
|
+function metatag_update_7037() {
|
|
|
|
+ variable_set('menu_rebuild_needed', TRUE);
|
|
|
|
+}
|
|
|
|
|
|
- // Loop over the values and correct them.
|
|
|
|
- if ($records->rowCount() == 0) {
|
|
|
|
- drupal_set_message($none_message);
|
|
|
|
|
|
+/**
|
|
|
|
+ * Manually enable all content types, vocabularies and the user entity to help
|
|
|
|
+ * resolve issues from 1.5's architecture change.
|
|
|
|
+ */
|
|
|
|
+function metatag_update_7038() {
|
|
|
|
+ foreach (array('node', 'taxonomy_term', 'user') as $entity_type) {
|
|
|
|
+ // Enable the main entity type.
|
|
|
|
+ $variable_name = 'metatag_enable_' . $entity_type;
|
|
|
|
+ variable_set($variable_name, TRUE);
|
|
|
|
+
|
|
|
|
+ // Update each entity bundle too.
|
|
|
|
+ $entity_info = entity_get_info($entity_type);
|
|
|
|
+ if (!empty($entity_info['bundles'])) {
|
|
|
|
+ foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
|
|
|
|
+ $variable_name = 'metatag_enable_' . $entity_type . '__' . $bundle_name;
|
|
|
|
+ variable_set($variable_name, TRUE);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- else {
|
|
|
|
- $keys = array('cid');
|
|
|
|
|
|
+}
|
|
|
|
|
|
- // Loop over the values and correct them.
|
|
|
|
- $counter = 0;
|
|
|
|
- foreach ($records as $record) {
|
|
|
|
- $record->config = unserialize($record->config);
|
|
|
|
- if (isset($record->config['copyright'])) {
|
|
|
|
- $record->config['rights'] = $record->config['copyright'];
|
|
|
|
- unset($record->config['copyright']);
|
|
|
|
- drupal_write_record('metatag_config', $record, $keys);
|
|
|
|
- $counter++;
|
|
|
|
|
|
+/**
|
|
|
|
+ * Reload some meta tag caches.
|
|
|
|
+ */
|
|
|
|
+function metatag_update_7039() {
|
|
|
|
+ foreach (language_list() as $langcode => $language) {
|
|
|
|
+ cache_clear_all('info:' . $langcode, 'cache_metatag');
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Fix robots meta tags that might have been broken when they were imported
|
|
|
|
+ * from Nodewords.
|
|
|
|
+ */
|
|
|
|
+function metatag_update_7040(&$sandbox) {
|
|
|
|
+ // Process records by groups of 10 (arbitrary value).
|
|
|
|
+ // When a group is processed, the batch update engine determines whether it
|
|
|
|
+ // should continue processing in the same request or provide progress
|
|
|
|
+ // feedback to the user and wait for the next request.
|
|
|
|
+ $limit = 10;
|
|
|
|
+ // When ran through Drush it's Ok to process a larger number of objects at a
|
|
|
|
+ // time.
|
|
|
|
+ if (drupal_is_cli()) {
|
|
|
|
+ $limit = 100;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Use the sandbox at your convenience to store the information needed
|
|
|
|
+ // to track progression between successive calls to the function.
|
|
|
|
+ if (!isset($sandbox['progress'])) {
|
|
|
|
+ // The count of records visited so far.
|
|
|
|
+ $sandbox['progress'] = 0;
|
|
|
|
+
|
|
|
|
+ // Get a count of {metatag} records that have a robots meta tag definition
|
|
|
|
+ // that is not in the correct format.
|
|
|
|
+ $records = db_select('metatag', 'm')
|
|
|
|
+ ->fields('m')
|
|
|
|
+ ->condition('m.data', '%:6:"robots";%', 'LIKE')
|
|
|
|
+ ->condition('m.data', '%:6:"robots";a:1:{s:5:"value";%', 'NOT LIKE')
|
|
|
|
+ ->countQuery()
|
|
|
|
+ ->execute()
|
|
|
|
+ ->fetchField();
|
|
|
|
+
|
|
|
|
+ // If there's no data, don't bother with the extra work.
|
|
|
|
+ if (empty($records)) {
|
|
|
|
+ watchdog('metatag', 'Update 7040: No robots meta tags need to be fixed.', array(), WATCHDOG_INFO);
|
|
|
|
+ if (drupal_is_cli()) {
|
|
|
|
+ drupal_set_message(t('Update 7040: No robots meta tags need to be fixed.'));
|
|
}
|
|
}
|
|
|
|
+ return t('No robots meta tags need to be fixed.');
|
|
}
|
|
}
|
|
- if ($counter == 0) {
|
|
|
|
- drupal_set_message($none_message);
|
|
|
|
|
|
+
|
|
|
|
+ // Total records that must be visited.
|
|
|
|
+ $sandbox['max'] = $records;
|
|
|
|
+
|
|
|
|
+ // A place to store messages during the run.
|
|
|
|
+ $sandbox['messages'] = array();
|
|
|
|
+
|
|
|
|
+ // An initial record of the number of records to be updated.
|
|
|
|
+ watchdog('metatag', 'Update 7040: !count records to examine.', array('!count' => $sandbox['max']), WATCHDOG_INFO);
|
|
|
|
+ if (drupal_is_cli()) {
|
|
|
|
+ drupal_set_message(t('Update 7040: !count records to examine.', array('!count' => $sandbox['max'])));
|
|
}
|
|
}
|
|
- else {
|
|
|
|
- drupal_set_message(t('Converted the "copyright" meta tag for @count configurations to the correct "rights" meta tag.', array('@count' => $counter)));
|
|
|
|
|
|
+
|
|
|
|
+ // Log how many records are fixed.
|
|
|
|
+ $sandbox['fixed'] = 0;
|
|
|
|
+
|
|
|
|
+ // Because a lot of other processing happens on the first iteration, just do
|
|
|
|
+ // ten.
|
|
|
|
+ $limit = 10;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Get a list of records that need to be fixed.
|
|
|
|
+ $records = db_select('metatag', 'm')
|
|
|
|
+ ->fields('m')
|
|
|
|
+ ->condition('m.data', '%:6:"robots";%', 'LIKE')
|
|
|
|
+ ->condition('m.data', '%:6:"robots";a:1:{s:5:"value";%', 'NOT LIKE')
|
|
|
|
+ ->range(0, $limit)
|
|
|
|
+ ->execute();
|
|
|
|
+
|
|
|
|
+ // Set default values.
|
|
|
|
+ foreach ($records as $record) {
|
|
|
|
+ // Extract the record.
|
|
|
|
+ $record->data = unserialize($record->data);
|
|
|
|
+
|
|
|
|
+ // See if the record needs to be fixed.
|
|
|
|
+ if (!empty($record->data['robots']) && empty($record->data['robots']['value'])) {
|
|
|
|
+ // Fix the record.
|
|
|
|
+ $robots = $record->data['robots'];
|
|
|
|
+ $record->data['robots'] = array(
|
|
|
|
+ 'value' => $robots,
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ // Update the database.
|
|
|
|
+ db_update('metatag')
|
|
|
|
+ ->fields(array('data' => serialize($record->data)))
|
|
|
|
+ ->condition('entity_type', $record->entity_type)
|
|
|
|
+ ->condition('entity_id', $record->entity_id)
|
|
|
|
+ ->condition('revision_id', $record->revision_id)
|
|
|
|
+ ->condition('language', $record->language)
|
|
|
|
+ ->execute();
|
|
|
|
+
|
|
|
|
+ // Clear the cache for this entity.
|
|
|
|
+ entity_get_controller($record->entity_type)->resetCache(array($record->entity_id));
|
|
|
|
+
|
|
|
|
+ // Update our progress information.
|
|
|
|
+ $sandbox['fixed']++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Update our progress information.
|
|
|
|
+ $sandbox['progress']++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Set the "finished" status, to tell batch engine whether this function
|
|
|
|
+ // needs to run again. If you set a float, this will indicate the progress of
|
|
|
|
+ // the batch so the progress bar will update.
|
|
|
|
+ $sandbox['#finished'] = ($sandbox['progress'] >= $sandbox['max']) ? TRUE : ($sandbox['progress'] / $sandbox['max']);
|
|
|
|
+
|
|
|
|
+ // Only display a status message if process finished.
|
|
|
|
+ if ($sandbox['#finished'] === TRUE) {
|
|
|
|
+ // Clear all caches so the fixed data will be reloaded.
|
|
|
|
+ cache_clear_all('*', 'cache_metatag', TRUE);
|
|
|
|
+
|
|
|
|
+ // A final log of the number of records that were converted.
|
|
|
|
+ watchdog('metatag', 'Update 7040: !count records were fixed.', array('!count' => $sandbox['fixed']), WATCHDOG_INFO);
|
|
|
|
+ if (drupal_is_cli()) {
|
|
|
|
+ drupal_set_message(t('Update 7040: !count records were fixed.', array('!count' => $sandbox['fixed'])));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // hook_update_N() may optionally return a string which will be displayed
|
|
|
|
+ // to the user.
|
|
|
|
+ return t('Fixed the Metatag robots values for @count nodes.', array('@count' => $sandbox['fixed']));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Clear the Metatag cache.
|
|
|
|
|
|
+ * Rerun update 7018 that was fixed to run correctly when using Entity
|
|
|
|
+ * Translation. This may take some time.
|
|
*/
|
|
*/
|
|
-function metatag_update_7032() {
|
|
|
|
|
|
+function metatag_update_7041(&$sandbox) {
|
|
|
|
+ metatag_update_7018($sandbox);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Delete a deprecated variable and clear all Metatag caches.
|
|
|
|
+ */
|
|
|
|
+function metatag_update_7100() {
|
|
|
|
+ variable_del('metatag_translate_final_values');
|
|
|
|
+
|
|
|
|
+ // Clear all caches so that i18n support can be activated, if necessary.
|
|
cache_clear_all('*', 'cache_metatag', TRUE);
|
|
cache_clear_all('*', 'cache_metatag', TRUE);
|
|
- return t('All Metatag caches cleared.');
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * These originally removed the 'author' meta tag, but it was subsequently
|
|
|
|
- * decided that this was not the correct approach, that the meta tag should not
|
|
|
|
- * be removed after all.
|
|
|
|
- *
|
|
|
|
- * @see https://www.drupal.org/node/2330823
|
|
|
|
|
|
+ * Update i18n strings for all meta tags to use the new format.
|
|
*/
|
|
*/
|
|
-function metatag_update_7033() {
|
|
|
|
|
|
+function metatag_update_7101() {
|
|
|
|
+ if (!module_exists('locale') || !db_table_exists('locales_source')) {
|
|
|
|
+ return t('No translations to fix as the locale system is not enabled.');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Loop through each entity type. Not going to bother filtering this list,
|
|
|
|
+ // it'll only be a difference of a few entities anyway and the queries
|
|
|
|
+ // should be fairly quick.
|
|
|
|
+ foreach (entity_get_info() as $entity_type => $entity_info) {
|
|
|
|
+ // Entities must have bundles.
|
|
|
|
+ if (empty($entity_info['bundles'])) {
|
|
|
|
+ $entity_info['bundles'] = array(
|
|
|
|
+ $entity_type => $entity_type,
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ foreach ($entity_info['bundles'] as $bundle_type => $bundle_info) {
|
|
|
|
+ // Update {locales_source}, replace 'metatag:ENTITYTYPE:BUNDLE:tag' with
|
|
|
|
+ // 'metatag:metatag_config:ENTITYTYPE:BUNDLE:tag'.
|
|
|
|
+ db_query("UPDATE {locales_source}
|
|
|
|
+ SET location = REPLACE(location, 'metatag:{$entity_type}:{$bundle_type}:', 'metatag:metatag_config:{$entity_type}:{$bundle_type}:'),
|
|
|
|
+ context = REPLACE(context, '{$entity_type}:{$bundle_type}:', 'metatag_config:{$entity_type}:{$bundle_type}:')
|
|
|
|
+ WHERE textgroup = 'metatag'
|
|
|
|
+ AND location LIKE 'metatag:{$entity_type}:{$bundle_type}:%'");
|
|
|
|
+
|
|
|
|
+ // Update {locales_source}, replace 'metatag:ENTITYTYPE:tag' with
|
|
|
|
+ // 'metatag:metatag_config:ENTITYTYPE:tag'.
|
|
|
|
+ db_query("UPDATE {locales_source}
|
|
|
|
+ SET location = REPLACE(location, 'metatag:{$entity_type}:', 'metatag:metatag_config:{$entity_type}:'),
|
|
|
|
+ context = REPLACE(context, '{$entity_type}:', 'metatag_config:{$entity_type}:')
|
|
|
|
+ WHERE textgroup = 'metatag'
|
|
|
|
+ AND location LIKE 'metatag:{$entity_type}:%'");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Update {locales_source}, replace 'metatag:metatag:' with
|
|
|
|
+ // 'metatag:output:'.
|
|
|
|
+ db_query("UPDATE {locales_source}
|
|
|
|
+ SET location = REPLACE(location, 'metatag:metatag:', 'metatag:output:'),
|
|
|
|
+ context = REPLACE(context, 'metatag:', 'output:')
|
|
|
|
+ WHERE textgroup = 'metatag'
|
|
|
|
+ AND location LIKE 'metatag:metatag:%'");
|
|
}
|
|
}
|
|
-function metatag_update_7034() {
|
|
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Re-run update 7101.
|
|
|
|
+ */
|
|
|
|
+function metatag_update_7102() {
|
|
|
|
+ metatag_update_7101();
|
|
}
|
|
}
|
|
-function metatag_update_7035() {
|
|
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Clear all metatag caches so the new entity caching structure takes over.
|
|
|
|
+ */
|
|
|
|
+function metatag_update_7103() {
|
|
|
|
+ cache_clear_all('*', 'cache_metatag', TRUE);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Remove the entity revision ID from the translation strings.
|
|
|
|
+ */
|
|
|
|
+function metatag_update_7104(&$sandbox) {
|
|
|
|
+ // Verify that locales are being used in the first place.
|
|
|
|
+ if (!module_exists('locale') || !db_table_exists('locales_source')) {
|
|
|
|
+ return t('Metatag: No translations to fix as the locale system is not enabled.');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // No need to do anything if output translation is disabled.
|
|
|
|
+ if (!variable_get('metatag_i18n_translate_output', FALSE)) {
|
|
|
|
+ return t('Metatag: Output translation is disabled, so no need to update anything.');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Process records by groups of 10 (arbitrary value).
|
|
|
|
+ // When a group is processed, the batch update engine determines whether it
|
|
|
|
+ // should continue processing in the same request or provide progress
|
|
|
|
+ // feedback to the user and wait for the next request.
|
|
|
|
+ $limit = 10;
|
|
|
|
+ // When ran through Drush it's Ok to process a larger number of objects at a
|
|
|
|
+ // time.
|
|
|
|
+ if (drupal_is_cli()) {
|
|
|
|
+ $limit = 100;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Use the sandbox at your convenience to store the information needed
|
|
|
|
+ // to track progression between successive calls to the function.
|
|
|
|
+ if (!isset($sandbox['progress'])) {
|
|
|
|
+ // The count of records visited so far.
|
|
|
|
+ $sandbox['progress'] = 0;
|
|
|
|
+
|
|
|
|
+ // Total records that must be visited.
|
|
|
|
+ $sandbox['max'] = db_query("SELECT COUNT(lid)
|
|
|
|
+ FROM {locales_source}
|
|
|
|
+ WHERE textgroup = 'metatag'
|
|
|
|
+ AND context LIKE 'output:%:%:%:%'")->fetchField();
|
|
|
|
+
|
|
|
|
+ // If there's no data, don't bother with the extra work.
|
|
|
|
+ if (empty($sandbox['max'])) {
|
|
|
|
+ watchdog('metatag', 'Update 7104: No nodes need the translation entity string fixed.', array(), WATCHDOG_INFO);
|
|
|
|
+ if (drupal_is_cli()) {
|
|
|
|
+ drupal_set_message(t('Update 7104: No nodes need the translation entity string fixed.'));
|
|
|
|
+ }
|
|
|
|
+ return t('No nodes need the Metatag language values fixed.');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // A place to store messages during the run.
|
|
|
|
+ $sandbox['messages'] = array();
|
|
|
|
+
|
|
|
|
+ // An initial record of the number of records to be updated.
|
|
|
|
+ watchdog('metatag', 'Update 7104: !count records to update.', array('!count' => $sandbox['max']), WATCHDOG_INFO);
|
|
|
|
+ if (drupal_is_cli()) {
|
|
|
|
+ drupal_set_message(t('Update 7104: !count records to update.', array('!count' => $sandbox['max'])));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Get a batch of records that need to be fixed.
|
|
|
|
+ $records = db_query_range("SELECT lid, location, context
|
|
|
|
+ FROM {locales_source}
|
|
|
|
+ WHERE textgroup = 'metatag'
|
|
|
|
+ AND context LIKE 'output:%:%:%:%'", 0, $limit);
|
|
|
|
+
|
|
|
|
+ // Update each of the records.
|
|
|
|
+ foreach ($records as $record) {
|
|
|
|
+ $old_location = '/metatag:output:([^:]*):([^:]*):([^:]*):([^:]*)/';
|
|
|
|
+ $new_location = 'metatag:output:$1:$2:$4';
|
|
|
|
+ $location = preg_replace($old_location, $new_location, $record->location);
|
|
|
|
+ $old_context = '/output:([^:]*):([^:]*):([^:]*):([^:]*)/';
|
|
|
|
+ $new_context = 'output:$1:$2:$4';
|
|
|
|
+ $context = preg_replace($old_context, $new_context, $record->context);
|
|
|
|
+ drupal_set_message($location);
|
|
|
|
+ drupal_set_message($context);
|
|
|
|
+ db_update('locales_source')
|
|
|
|
+ ->fields(array(
|
|
|
|
+ 'location' => $location,
|
|
|
|
+ 'context' => $context,
|
|
|
|
+ ))
|
|
|
|
+ ->condition('lid', $record->lid)
|
|
|
|
+ ->execute();
|
|
|
|
+
|
|
|
|
+ // Update our progress information.
|
|
|
|
+ $sandbox['progress']++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Set the "finished" status, to tell batch engine whether this function
|
|
|
|
+ // needs to run again. If you set a float, this will indicate the progress of
|
|
|
|
+ // the batch so the progress bar will update.
|
|
|
|
+ $sandbox['#finished'] = ($sandbox['progress'] >= $sandbox['max']) ? TRUE : ($sandbox['progress'] / $sandbox['max']);
|
|
|
|
+
|
|
|
|
+ if ($sandbox['#finished']) {
|
|
|
|
+ // Clear all caches so the fixed data will be reloaded.
|
|
|
|
+ cache_clear_all('*', 'cache_metatag', TRUE);
|
|
|
|
+
|
|
|
|
+ // hook_update_N() may optionally return a string which will be displayed
|
|
|
|
+ // to the user.
|
|
|
|
+ return t('Fixed the Metatag language values for @count nodes.', array('@count' => $sandbox['progress']));
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Fix the output translation strings.
|
|
|
|
+ */
|
|
|
|
+function metatag_update_7105() {
|
|
|
|
+ if (!module_exists('locale') || !db_table_exists('locales_source')) {
|
|
|
|
+ return t('No translations to fix as the locale system is not enabled.');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ db_query("UPDATE {locales_source}
|
|
|
|
+ SET location = REPLACE(location, 'metatag:metatag:', 'metatag:output:'),
|
|
|
|
+ context = REPLACE(context, 'metatag:', 'output:')
|
|
|
|
+ WHERE textgroup = 'metatag'
|
|
|
|
+ AND location LIKE 'metatag:metatag:%'");
|
|
|
|
+
|
|
|
|
+ return t('Fixed the Metatag output strings.');
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * The output translation strings were renamed to something shorter, so rerun
|
|
|
|
+ * update 7105.
|
|
|
|
+ */
|
|
|
|
+function metatag_update_7106() {
|
|
|
|
+ return metatag_update_7105();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Fix the global config translation strings.
|
|
|
|
+ */
|
|
|
|
+function metatag_update_7107() {
|
|
|
|
+ if (!module_exists('locale') || !db_table_exists('locales_source')) {
|
|
|
|
+ return t('No translations to fix as the locale system is not enabled.');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ db_query("UPDATE {locales_source}
|
|
|
|
+ SET location = REPLACE(location, 'metatag:global:', 'metatag:metatag_config:global:'),
|
|
|
|
+ context = REPLACE(context, 'global:', 'metatag_config:global:')
|
|
|
|
+ WHERE textgroup = 'metatag'
|
|
|
|
+ AND location LIKE 'metatag:global:%'");
|
|
|
|
+
|
|
|
|
+ return t('Fixed the Metatag global config string translations.');
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Delete output translations if it's disabled.
|
|
|
|
+ */
|
|
|
|
+function metatag_update_7108() {
|
|
|
|
+ if (!module_exists('locale') || !db_table_exists('locales_source')) {
|
|
|
|
+ return t('No translations to fix as the locale system is not enabled.');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // If the output-translation option is enabled then don't delete anything.
|
|
|
|
+ if (variable_get('metatag_i18n_translate_output', FALSE)) {
|
|
|
|
+ return t("Metatag: Not deleting output translations because that option is enabled.");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $lids = db_select('locales_source', 'ls')
|
|
|
|
+ ->fields('ls', array('lid'))
|
|
|
|
+ ->condition('ls.textgroup', 'metatag')
|
|
|
|
+ ->condition('ls.context', 'output:%', 'LIKE')
|
|
|
|
+ ->execute()
|
|
|
|
+ ->fetchCol();
|
|
|
|
+
|
|
|
|
+ if (!empty($lids)) {
|
|
|
|
+ // Delete records in the tables in reverse order, so that if the query fails
|
|
|
|
+ // and has to be reran it'll still find records. But it should be ok.
|
|
|
|
+ if (db_table_exists('i18n_string')) {
|
|
|
|
+ db_delete('i18n_string')
|
|
|
|
+ ->condition('lid', $lids)
|
|
|
|
+ ->execute();
|
|
|
|
+ }
|
|
|
|
+ db_delete('locales_target')
|
|
|
|
+ ->condition('lid', $lids)
|
|
|
|
+ ->execute();
|
|
|
|
+ db_delete('locales_source')
|
|
|
|
+ ->condition('lid', $lids)
|
|
|
|
+ ->execute();
|
|
|
|
+ return t('Metatag: Removed @count output translation records that were not needed.', array('@count' => count($lids)));
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return t('Metatag; No output translation records needed to be removed.');
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Rename the 'icon_any' meta tag to 'mask-icon' in the entity records.
|
|
|
|
+ */
|
|
|
|
+function metatag_update_7109(&$sandbox) {
|
|
|
|
+ module_load_include('install', 'metatag');
|
|
|
|
+ $old_tag = 'icon_any';
|
|
|
|
+ $new_tag = 'mask-icon';
|
|
|
|
+ return metatag_update_replace_meta_tag($sandbox, $old_tag, $new_tag);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Rename the 'icon_any' meta tag to 'mask-icon' in the configs.
|
|
|
|
+ */
|
|
|
|
+function metatag_update_7110() {
|
|
|
|
+ module_load_include('install', 'metatag');
|
|
|
|
+ $old_tag = 'icon_any';
|
|
|
|
+ $new_tag = 'mask-icon';
|
|
|
|
+ return metatag_update_replace_config($old_tag, $new_tag);
|
|
}
|
|
}
|