/[drupal]/contributions/modules/og_galleries/og_galleries.install
ViewVC logotype

Contents of /contributions/modules/og_galleries/og_galleries.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.8 - (show annotations) (download) (as text)
Fri Jul 24 12:29:05 2009 UTC (4 months ago) by karens
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +121 -21 lines
File MIME type: text/x-php
Add migration code to migrate data to Views Gallery OG. It won't work in many cases, but will work in some.
1 <?php
2 // $Id: og_galleries.install,v 1.5.2.2 2007/02/05 14:04:21 karens Exp $
3
4 function og_galleries_uninstall() {
5 include_once(drupal_get_path('module', 'og_galleries') .'/og_galleries.module');
6 $result = db_query("SELECT * FROM {og_galleries} ORDER BY gid");
7 while ($arr = db_fetch_array($result)) {
8 taxonomy_del_vocabulary($arr['vid']);
9 }
10 db_query("DELETE FROM {system} WHERE name='og_galleries'");
11 db_query("DELETE FROM {variable} WHERE name LIKE '%og_galleries%'");
12 @db_query("DROP TABLE {og_galleries}");
13
14 if ($views = og_galleries_get_all_views()) {
15 foreach ($views as $view_name) {
16 $view = views_get_view($view_name);
17 _views_delete_view((object) $view);
18 }
19 views_invalidate_cache();
20 }
21 menu_rebuild();
22 drupal_set_message(t('OG Galleries has been uninstalled. Gallery content been unlinked from its galleries, but not removed. All gallery labels, descriptions, variables, views, and tables have been removed.'));
23 }
24
25 /**
26 * Migrate OG Galleries to Views Gallery OG.
27 */
28 function og_galleries_update_6000() {
29 // Set the name of the image field on the existing
30 // node that should be migrated to become the
31 // gallery image on the new node.
32 variable_set('og_galleries_old_image_field', 'field_image');
33
34 $ret = array();
35 if (!db_table_exists('og_galleries')) {
36 $ret[] = array('success' => TRUE, 'query' => t('No update is possible, og_galleries table is empty.'));
37 return $ret;
38 }
39 if (!module_exists('views_gallery_og')) {
40 $ret[] = array('success' => FALSE, 'query' => t('You must install Views Gallery OG before this module can be migrated.'));
41 return $ret;
42 }
43 module_load_install('views_gallery');
44 module_load_install('views_gallery_og');
45
46 // Get the vid of the public vocabulary.
47 $public_vid = variable_get('og_galleries_public_vocabulary', 0);
48
49 // Get the vids of the group galleries.
50 $result = db_query("SELECT * FROM {og_galleries} ORDER BY gid");
51 while ($arr = db_fetch_array($result)) {
52 $gid = $arr['gid'];
53 $vid = $arr['vid'];
54
55 // Create galleries for all terms in this vocabulary
56 // that have nodes.
57 $result1 = db_query("SELECT td.tid, td.name, td.description FROM {term_data} td WHERE td.vid=%d ORDER BY td.vid", $vid);
58 while($arr1 = db_fetch_object($result1)) {
59 if (!empty($gid)) {
60 $group_node = node_load($gid);
61 $params = array();
62 $params['title'] = $arr1->name;
63 $params['body'] = $arr1->description;
64 $gallery = views_gallery_og_create($gid, $arr1->name, FALSE, $params);
65 }
66 else {
67 $group_node = NULL;
68 $voc = taxonomy_vocabulary_load($vid);
69 $gallery = og_galleries_create_public($voc);
70 }
71
72 // Find all nodes with this term and update them
73 // with group information.
74 $result2 = db_query("SELECT t.nid, t.tid, n.type FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE t.vid=%d", $vid);
75 while($arr2 = db_fetch_object($result2)) {
76 og_galleries_migrate_node($arr2, $vid, $gid, $group_node, $gallery);
77 }
78 }
79 taxonomy_del_vocabulary($vid);
80 }
81
82 return $ret;
83 }
84
85 function og_galleries_create_public($voc) {
86 global $user;
87
88 $node = new stdClass();
89 $node->type = views_gallery_gallery_type();
90 $node->title = $voc->name;
91 $node->uid = $user->uid;
92 $node->name = $user->name;
93 $node->status = 1;
94 $node->comment = 0;
95 $node->promote = 1;
96 $node->sticky = 1;
97 $node->revision = 1;
98 $node->format = 1;
99 $node->comment = COMMENT_NODE_DISABLED;
100
101 node_save($node);
102 drupal_set_message(t('Public gallery node @nid created.', array('@nid' => $node->nid)));
103 return $node;
104 }
105
106 function og_galleries_migrate_node($arr, $vid, $gid, $group_node, $gallery) {
107 $nid = $arr->nid;
108 $tid = $arr->tid;
109
110 $node = node_load($nid);
111 $node->type = views_gallery_image_type();
112 unset($node->taxonomy[$tid]);
113
114 $node->field_gallery[0]['nid'] = $gallery->nid;
115 $old = variable_get('og_galleries_old_image_field', 'field_image');
116 $node->field_gallery_image = $node->$old;
117
118 if (!empty($group_node)) {
119 if (empty($node->og_groups)) {
120 $node->og_groups = array();
121 }
122 if (empty($node->og_groups_both)) {
123 $node->og_groups_both = array();
124 }
125 $node->og_groups[$gid] = $gid;
126 $node->og_groups_both[$gid] = $group_node->title;
127
128 $is_public = db_result(db_query("SELECT COUNT(*) FROM {term_node} WHERE nid=%d AND vid=%d", $nid, $public_vid));
129 $node->og_public = empty($is_public);
130 }
131
132 node_save($node);
133
134 // Delete the finished term_nodes so we don't
135 // try to reprocess them as we move through the
136 // batch.
137 // Don't delete the public nodes, we need them to see
138 // if group node items have a public option.
139 if ($vid != $public_vid) {
140 db_query("DELETE FROM {term_node} WHERE nid=%d AND vid=%d AND tid=%d", $nid, $vid, $tid);
141 }
142 }

  ViewVC Help
Powered by ViewVC 1.1.2