Friday, August 6, 2010

Drupal menu disappeared.

I am not an expert of Drupal. Actually, I am new to Drupal. Somehow, someway, our team selected Drupal for our interactive method to collaborate with entire company. Make sense because we don't want to spend whole lot of time just for method. We want the result.

While I was enabling "Views" module in drupal, it acted up. Views did not show up. So, I disabled Views and tried to re-install. But, right after disabling Views, menu is screwed up. Like this.

I couldn't administer menu, modules, and theme any more! That is a disaster for admin user. I was so tempted to re-install drupal, but then, migrating old database to new one is another challenge. Old one was in dev, but we already collected some data. And, old site were configured too.
So, only option is "FIX". But, fixing a software that I never deal with was a quite discouraging moment. I prepared fresh install of drupal, and diff'd the files. Files looked similar. Then, all modification must be in the database.
So, I wrote a database diff tool.

Successfully, I found it is because menu_router table is corrupted. I restored.
Here is the sample code that I used:

#!/usr/bin/env python

import MySQLdb
import os
import sys

def main():
cn1 = MySQLdb.connect(host="", db="drupal_prod")
cn2 = MySQLdb.connect(host="", db="drupal_dev")
print >>sys.stderr, "ERROR: connection"

while 1:
table = raw_input("Table name: ")
sql = "select count(*) from %s" % table

cur1 = cn1.cursor()
cur2 = cn2.cursor()

r1 = cur1.fetchone()
r2 = cur2.fetchone()
if r1[0] == r2[0] == 0:
print "SAME!"

if r1[0] == r2[0]:
print "Same COUNT! "
print "DIFF Found! "

inp = raw_input("specific sql? ")
if inp.strip() == '':
sql = "select * from %s" % table
sql = inp
print "SQL used: %s; " % sql

while 1:
r1 = cur1.fetchone()
r2 = cur2.fetchone()

if r1 is None and r2 is None:

if r1.__str__() != r2.__str__():
print "* ", r1, "\n", "# ", r2

print "Repeat- SQL Used:\n%s;" % sql

if __name__ == '__main__':

No comments: