The 7013 update hook isn't working anymore after the revision support was added. The revision_id column doesn't exist yet, which causes problem when we load the entities.

We probably can't use entity_load when running the update since it will cause metatag to try to load things with the revision_id.

Comments

fabsor’s picture

Actually, this could break things back to 7009, since remove_dupes() can call entity_load as well.

fabsor’s picture

Status: Active » Needs review
StatusFileSize
new4.17 KB

Here is a patch that runs 7015 earlier, by invoking it programmatically that solved the problem for me. Not a very clean solution but all other solutions would involve avoiding entity api, which can be problematic for some entity types.

damienmckenna’s picture

Priority: Normal » Major
Status: Needs review » Needs work
Parent issue: » #2117171: Plan for 7.x-1.0-beta8 on 2013-01-15

Oh crikey! Thanks for catching this bug! Yeah, need to fix this before beta8. I've bumped it to major as it has the potential to screw up sites.

The patch could use a little tweaking, mainly that the metatag_skip_update_7015 logic could be moved into metatag_update_7015 itself.

damienmckenna’s picture

Title: Metatag update 7013 broken after the revision support was added » Older Metatag updates broken after revision support was added
damienmckenna’s picture

Status: Needs work » Needs review
StatusFileSize
new4.35 KB

How about this?

hyperglide’s picture

How best to test this patch? These updates are post beta 7?

damienmckenna’s picture

Every patch will require the current -dev codebase.

hyperglide’s picture

Patch #5 could not be applied to the Jan 14 Dev.

output of patch.rej

--- metatag.install
+++ metatag.install
@@ -221,6 +221,10 @@
   variable_del('metatag_schema_installed');
   // Used to control whether 403/404 pages are cached.
   variable_del('metatag_cache_error_pages');
+
+  // Temp variables, just in case they weren't removed already.
+  variable_del('metatag_skip_update_7015');
+  variable_del('metatag_skip_update_7017');
 }
 
 /**
@@ -459,6 +463,9 @@
  */
 function metatag_update_7009() {
   if (module_exists('taxonomy')) {
+    // Fix the {metatag} table first.
+    metatag_update_7015();
+
     // Remove duplicates.
     _metatag_remove_dupes('taxonomy_term');
   }
@@ -475,6 +482,9 @@
  * Fix {metatag} records for users.
  */
 function metatag_update_7010() {
+  // Fix the {metatag} table first.
+  metatag_update_7015();
+
   // Remove duplicates.
   _metatag_remove_dupes('user');
 
@@ -489,6 +499,9 @@
  * Fix {metatag} records for nodes.
  */
 function metatag_update_7011(&$sandbox) {
+  // Fix the {metatag} table first.
+  metatag_update_7015();
+
   // Only proceed if Entity_Translation is not enabled as it allows each node
   // record to have multiple languages available.
   if (module_exists('entity_translation')) {
@@ -598,6 +611,9 @@
  * Remove duplicate {metatag} records for non-core entities.
  */
 function metatag_update_7012() {
+  // Fix the {metatag} table first.
+  metatag_update_7015();
+
   if (module_exists('entity_translation')) {
     drupal_set_message(t("Entity Translation is enabled, duplicate meta tags will not be removed for custom entities, to avoid accidental dataloss."));
     return;
@@ -628,6 +644,9 @@
  * take a while, depending on how much data needs to be converted.
  */
 function metatag_update_7013(&$sandbox) {
+  // Fix the {metatag} table first.
+  metatag_update_7015();
+
   if (module_exists('entity_translation')) {
     drupal_set_message(t("Entity Translation is enabled, meta tags will not be updated for custom entities, to avoid accidental dataloss."));
     return;
@@ -919,26 +938,34 @@
  * keys accordingly.
  */
 function metatag_update_7015() {
-  // Tell update 7016 that it isn't needed.
-  variable_set('metatag_skip_update_7017', TRUE);
+  if (!variable_get('metatag_skip_update_7015', FALSE)) {
+    // Make sure this update script isn't executed more than once.
+    variable_set('metatag_skip_update_7015', TRUE);
 
-  // Add the new field.
-  db_add_field('metatag', '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.',
-    ));
+    // Tell update 7017 that it isn't needed.
+    variable_set('metatag_skip_update_7017', TRUE);
+
+    // Add the new field.
+    db_add_field('metatag', '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.',
+      ));
 
-  // Remove the existing primary key. This may take some work so it can be
-  // database agnostic, i.e. some databases will not like it.
-  db_drop_primary_key('metatag');
+    // Remove the existing primary key. This may take some work so it can be
+    // database agnostic, i.e. some databases will not like it.
+    db_drop_primary_key('metatag');
 
-  // Add the new primary key.
-  db_add_primary_key('metatag', array('entity_type', 'entity_id', 'revision_id', 'language'));
+    // Add the new primary key.
+    db_add_primary_key('metatag', array('entity_type', 'entity_id', 'revision_id', 'language'));
 
-  drupal_set_message(t('Added the {metatag}.revision_id field.'));
+    drupal_set_message(t('Added the {metatag}.revision_id field.'));
+  }
+  else {
+    variable_del('metatag_skip_update_7015');
+  }
 }
 
 /**
@@ -1193,3 +1220,10 @@
   cache_clear_all('*', 'cache_metatag', TRUE);
   return t('All Metatag caches cleared.');
 }
+
+/**
+ * A minor bit of tidy-up after update 7015.
+ */
+function metatag_update_7022() {
+  variable_del('metatag_skip_update_7015');
+}
damienmckenna’s picture

You might need to try downloading the code from git, it's working for me :-\

hyperglide’s picture

Nope. I just cloned the git:

git clone --branch 7.x-1.x http://git.drupal.org/project/metatag.git

Same issue.
Hunk #1 FAILED at 221.
Hunk #2 FAILED at 459.
Hunk #3 FAILED at 475.
Hunk #4 FAILED at 489.
Hunk #5 FAILED at 598.
Hunk #6 FAILED at 628.
Hunk #7 FAILED at 919.
Hunk #8 FAILED at 1193.

damienmckenna’s picture

I just did the same thing again, it worked fine. Do you have anything set up in your git global config to auto-change line endings? Are you able to apply other patches?

damienmckenna’s picture

Status: Needs review » Fixed

Committed! Thanks fabsor!

hyperglide’s picture

No. Yes. Same environment as other testing. See you committed it so :-)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.