I just updated OG from 7.x-2.0-beta2 to 7.x-2.3. After updating og_menu from 7.x-3.x-dev (datestamp 1347238034 2012-09-10) to 7.x-3.0-rc2, I'm unable to complete a DB update. The first time running drush updb, I see:

The following updates are pending:

og_menu module : 
  7300 -   Update og_menu schema to store group type and use etid instead of deprecated gid. 
  7301 -   Enable OG Menu functionality for all group content types (backwards compatibility). 
  7302 -   Enable OG Menu Default Links module if needed (backwards compatibility). 

Do you wish to run all pending updates? (y/n): y
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'default.og' doesn't exist                               [error]
Performed update: og_menu_update_7300                                                                              [ok]
Finished performing updates.                                                                                       [ok]

Subsequent attempts yield:

Do you wish to run all pending updates? (y/n): y
Cannot add field <em class="placeholder">og_menu</em>.<em class="placeholder">group_type</em>: field already       [error]
exists.
Performed update: og_menu_update_7300                                                                              [ok]
Finished performing updates.                                                                                       [ok]

I don't have the og table in my DB and it's not in the og schema. (for either 7.x-2.0-beta2 or 7.x-2.3)

The `og` table was added in og_update_7000() for people upgrading from d6 but AFAICT not referenced after that. Still digging...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ezheidtmann’s picture

Title: og_menu_update_7300() fails » og_menu_update_7300() fails when upgrading from 7.x-3.x-dev

It appears that update 7300 is intended for poor souls who update from OG1 to OG2 and update from og_menu 2 to og_menu 3. That's not my case here, so I skipped the 7300 update with this SQL:

  UPDATE system SET schema_version = 7300 WHERE name = 'og_menu';

That eliminates the error message, but now the og_menu table is missing the group_type column. Ack.

ezheidtmann’s picture

I've opted to not upgrade og_menu at this time, but I look forward to upgrading someday.

rv0’s picture

Assigned: Unassigned » rv0

todo ;)

rv0’s picture

Issue summary: View changes

Updated issue summary.

troybthompson’s picture

Any progress on this? I'm having the same problem. Is the table necessary or can I use the workaround above?

rv0’s picture

So basically this happens when updating from 6.x to 7.x-3.x ?

troybthompson’s picture

I don't believe this particular site used OG Menu when it was in Drupal 6, but that was before my time. Is there a test I can do to help you find out?

rv0’s picture

Tell me exactly what you did, from which version you updated (and perhaps you have a backup of the code you updated from? if so, please share)

I know this issue isn't happening on fresh installs so all additional info is welcome. I did 2 upgrades from 7.x-2.x so far without issues, so I don't know where to start looking.

troybthompson’s picture

I was originally using 7.x-3.x-dev (2012-Sep-09) and then did the system recommended upgrade to 7.x-3.0-rc3 and I got the series of errors above (how I found this thread). I also tried upgrading to the latest dev but had the same error. I'll try to get some database dumps if that will help.

rv0’s picture

Don't think I'll need the db backup.. I'l gonna check the version you mention

rv0’s picture

Could you guys try latest from git or wait for next dev reroll?
I added a simple check for the group_type
http://drupalcode.org/project/og_menu.git/blobdiff/2333b01faca2c2ae39cea...

ezheidtmann’s picture

Hey rv0 -- Unfortunately I don't have access to the original codebase or the current codebase (I'm off the project). But as I recall, this bug can be reproduced by doing an install of the 7.x-3.x branch before the update_7300 hook was added.

In other words, I believe this affects people who used the 7.x-3.x-dev before the 7300 update was written. Hope this helps.

-Evan

Corwin’s picture

I'm also having this issue

Corwin’s picture

drush pml | grep og
...
Organic groups OG Menu (og_menu) Module Enabled 7.x-3.0-rc4
...
Organic groups Organic groups (og) Module Enabled 7.x-2.5
...

Even after applying the patch to og_menu.install I still get this:

$ drush updb
 Og_menu  7300  Update og_menu schema to store group type and use etid instead of deprecated  gid.    
 Og_menu  7301  Enable OG Menu functionality for all group content types (backwards  compatibility).  
 Og_menu  7302  Enable OG Menu Default Links module if needed (backwards compatibility).              
 Og_menu  7303  Clear menu cache to enable admin page changes.
Do you wish to run all pending updates? (y/n): y
Cannot add field <em class="placeholder">og_menu</em>.<em class="placeholder">etid</em>: field already exists.                                                                           [error]
Performed update: og_menu_update_7300                                                                                                                                                    [ok]
Invalid argument supplied for foreach() query.inc:1853                                                                                                                                   [warning]
WD php: PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for   [error]
the right syntax to use near ')) AND (om.group_type = '0') ))' at line 2: SELECT om.gid AS gid, om.group_type AS group_type, om.menu_name AS menu_name, m.title AS title
FROM 
{og_menu} om
INNER JOIN {menu_custom} m ON om.menu_name = m.menu_name
WHERE (( (om.gid IN  ()) AND (om.group_type = :db_condition_placeholder_0) )); Array
(
    [:db_condition_placeholder_0] => 0
)
 in og_menu_get_group_menus() (line 934 of /var/www/html/prod2.wwwone1-dev.csun.edu/www/sites/all/modules/og_menu/og_menu.module).
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#039;)) AND (om.group_type = &#039;0&#039;) ))&#039; at line 2: SELECT om.gid AS gid, om.group_type AS group_type, om.menu_name AS menu_name, m.title AS title
FROM 
{og_menu} om
INNER JOIN {menu_custom} m ON om.menu_name = m.menu_name
WHERE (( (om.gid IN  ()) AND (om.group_type = :db_condition_placeholder_0) )); Array
(
    [:db_condition_placeholder_0] => 0
)
 in og_menu_get_group_menus() (line 934 of /var/www/html/prod2.wwwone1-dev.csun.edu/www/sites/all/modules/og_menu/og_menu.module).
Drush command terminated abnormally due to an unrecoverable error.                                                                                                                       [error]
Finished performing updates.
iaminawe’s picture

It worked for me to comment out lines 94-157 in og_menu.install - run the update and then comment the lines back in.
All my group menus are restored correctly and the site I am working on is a D6 to D7 upgrade.

rv0’s picture

@iaminawe in #14
There is no D6 to D7 upgrade path as mentioned on the frontpage
#1538556: Upgrade path from Drupal 6

iaminawe’s picture

I have it working properly in D7 and it came from a D6 site that I just upgraded using drush site upgrade and then OG & migrate module to get the groups migrated across.

In looking at the og_menu table from a fresh install of the module against what I currently had they were identical but the upgrade function in the lines above was doing some manipulation to the tables that didn't seem necessary judging by the structure I was looking at in the fresh install. I commented that function out, ran the remaining updates and commented it back in and ran update.php again this time with no errors

I should also mention I had all the menus in a feature too so not sure if that may have helped to keep their relationships intact but I now have each groups menu, from the D6 site showing correctly using the OG_menu block.

So not sure exactly what the magic combination there was but it worked for me and so I think an upgrade path does actually exist.

rv0’s picture

wel in a way the D6 version is much easier to update to 7.x-3.x, this due to architecture of OG2.x branch
I do recommend running https://drupal.org/project/schema to verify your tables

iaminawe’s picture

Thanks for the advice, I have run the schema module and verified that the tables match the schema provided by the module.

rv0’s picture

Status: Active » Postponed (maintainer needs more info)

rc5 release has been tagged.
@Corwin still having this issue?

rv0’s picture

Version: 7.x-3.0-rc2 » 7.x-3.x-dev
Corwin’s picture

The issue with existing fields group_type and etid are because 7300 creates them but then errors trying to join to the nonexistent table og.

the check:
if (!db_field_exists('og_menu', 'group_type')) {

was added, but then it just fails on adding etid so I would recommend adding the same check for etid.

The original/source issue is:
SELECT og.gid, og.etid FROM {og} as og, {og_menu} as og_menu WHERE og.gid = og_menu.gid and og_menu.etid = 0 ORDER BY og_menu.gid

mysql> desc og_menu;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| menu_name | varchar(32) | NO | PRI | | |
| gid | int(11) | NO | | NULL | |
| group_type | varchar(32) | NO | | | |
| etid | int(11) | NO | | NULL | |
+------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> desc og;
ERROR 1146 (42S02): Table 'drupal_prod2.og' doesn't exist

Thank you for your help rv0. :)

Corwin’s picture

I am able to get the DB updates to work by changing '{og}' to 'og_membership'

Corwin’s picture

7300 now completes, but corrupts the data.

Before og_menu updb:

SELECT * FROM og_menu WHERE menu_name="menu-main-menu";
+-----+----------------+
| gid | menu_name |
+-----+----------------+
| 2 | menu-main-menu |
+-----+----------------+

After og_menu updb:

SELECT * FROM og_menu WHERE menu_name="menu-main-menu";
+----------------+-----+------------+
| menu_name | gid | group_type |
+----------------+-----+------------+
| menu-main-menu | 281 | node |
+----------------+-----+------------+

Corwin’s picture

Does anyone know how to translate/convert this mumbo-jumbo into SQL?

db_update('og_menu')
->expression('gid', 'etid')
->execute();

I guess the code here (og_module.install lines 139-160) is looking up the value to put into group_type so I'll replace it with some legible and functioning SQL. I don't see any way this code could be doing anything remotely useful but that's probably why it's corrupting the data.

rv0’s picture

I am able to get the DB updates to work by changing '{og}' to 'og_membership'

that sounds really unhealthy
sorry about not having time to check this for you, soonest would be next week

rv0’s picture

Does anyone know how to translate/convert this mumbo-jumbo into SQL?

db_update('og_menu')
->expression('gid', 'etid')
->execute();

I guess the code here (og_module.install lines 139-160) is looking up the value to put into group_type so I'll replace it with some legible and functioning SQL. I don't see any way this code could be doing anything remotely useful but that's probably why it's corrupting the data.

Actually the code does exactly what the comments say.. First it creates a temporary etid column, later it replaces the gid column with values from the etid column
this is only relevant when updating from 7.x-2.x to 7.x-3.x

troybthompson’s picture

I'm not technical enough to follow the end of this thread. Is there a workaround even if there's not a simple patch at this point?

heddn’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
1.6 KB

My theory is that if the og table doesn't exist, then the migration from it isn't required. Here's a patch that does just that. Can I get a confirmation?

I'm not clear what the history of the site is through the various versions of og as this is a new site for me. But it came from og_menu 7.x-3.x-dev.

heddn’s picture

I did some more digging into this and testing of the results of applying the patch in #2093511-29: og_menu_update_7300() fails when upgrading from 7.x-3.x-dev. It won't work. And it is ugly. This one works, is a little less ugly and seems to confirm my suspicion that migrating content the og table isn't necessary.

  • rv0 committed 0847324 on 7.x-3.x authored by heddn
    Issue #2093511 by heddn | ezheidtmann: Fixed og_menu_update_7300() fails...
rv0’s picture

Status: Needs review » Fixed

Thanks, hopefully this solves the updating issue for everyone.

Status: Fixed » Closed (fixed)

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

troybthompson’s picture

I successfully upgraded to the latest dev this time. Thanks!