Деинсталляция WebFM из Drupal
Circumstantia
Дано
Сайт на Drupal 5.
Требуется
Превести сайт на Drupal 8.
Предварительный план действий
Drupal 5 -> Drupal 6 -> Drupal 8.
Проблема
В системе установлен пакет webfm, который не поддерживается после Drupal 6. Webfm ведёт свою базу файлов, и в тексте сайта ставит указание не на файл, на а запись в своей базе данных.
Solutio
При поиски решения проблемы были найдены следующие сайты:
Основываясь на них, набросал скипт webfm-fix
.
1#!/usr/bin/python2
2import MySQLdb
3
4# For REALY work set update = True
5update = False
6
7# connect to the databases
8
9db = MySQLdb.connect(
10 host="localhost", # your host, usually localhost
11 user="username", # your username
12 passwd="userpassword", # your password
13 db="database", # name of the data base
14 use_unicode=True, charset='utf8')
15
16cur = db.cursor()
17
18# get all the file ids and paths from the old webfm table
19
20filename_query = "SELECT fid, fpath FROM webfm_file"
21cur.execute(filename_query)
22
23fid_max = 0
24
25filenames = {}
26for row in cur.fetchall():
27 filenames[row[0]] = row[1]
28 if fid_max < row[0]:
29 fid_max = row[0]
30
31# find all webfm links and replace them with the actual file path
32
33query = "SELECT nid, body, teaser FROM node_revisions WHERE body like '%webfm_send%' OR teaser like '%webfm_send%'"
34cur.execute(query)
35
36for row in cur.fetchall():
37 entity_id = row[0]
38 body = row[1]
39 teaser = row[2]
40 for i in range(fid_max, 0, -1):
41 webfm1 = u'ru/webfm_send/' + str(i)
42 webfm2 = u'webfm_send/' + str(i)
43 webfm_list = [webfm1, webfm2]
44 for webfm in webfm_list:
45 if i in filenames:
46 sql_body = "UPDATE node_revisions SET body = REPLACE(body,'%s','%s') WHERE nid = %d" % (webfm,filenames[i],entity_id)
47 sql_teaser = "UPDATE node_revisions SET teaser = REPLACE(teaser,'%s','%s') WHERE nid = %d" % (webfm,filenames[i],entity_id)
48 if update:
49 try:
50 # Execute the SQL command
51 cur.execute(sql_body)
52 cur.execute(sql_teaser)
53 # Commit your changes in the database
54 db.commit()
55 except:
56 # Rollback in case there is any error
57 db.rollback()
58db.close()
При написании скрипта использовал следующую информацию: Where does Drupal store the content of a node’s body?
In Drupal 6, content of the node’s body is saved in node_revisions
table under body
field.
1node_revisions.body
In Drupal 7, content of the node’s body is saved in field_data_body
table under body_value
field. In case content revisions are there then it also saves the data in field_revision_body
table under body_value
field.
In Drupal 8, content of the node’s body is saved in node__body
table under body_value
field. In case content revisions are there then it also saves the data in node_revision__body
table under body_value
field.