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

Diff of /contributions/modules/og_collections/og_collections.install

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

revision 1.2.2.4, Mon Apr 7 02:25:27 2008 UTC revision 1.2.2.5, Mon Apr 7 10:16:52 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: og_collections.install,v 1.2.2.3 2008/04/07 00:20:00 sdboyer Exp $  // $Id: og_collections.install,v 1.2.2.4 2008/04/07 02:25:27 sdboyer Exp $
3    
4  function og_collections_install() {  function og_collections_install() {
5    switch ($GLOBALS['db_type']) {    switch ($GLOBALS['db_type']) {
# Line 11  function og_collections_install() { Line 11  function og_collections_install() {
11          pcpid int(11) NOT NULL,          pcpid int(11) NOT NULL,
12          pcpname varchar(32) NOT NULL,          pcpname varchar(32) NOT NULL,
13          grouptype varchar(32) NOT NULL DEFAULT 'default',          grouptype varchar(32) NOT NULL DEFAULT 'default',
14          version int(4) NOT NULL DEFAULT 0,          version int(4) NOT NULL DEFAULT 1,
15          PRIMARY KEY (did),          PRIMARY KEY (did),
16          KEY group_pcp_id (pcpid, grouptype)          KEY group_pcp_id (pcpid, grouptype)
17        ) /*!40100 DEFAULT CHARACTER SET utf8 */        ) /*!40100 DEFAULT CHARACTER SET utf8 */
# Line 55  EOT Line 55  EOT
55        ) /*!40100 DEFAULT CHARACTER SET utf8 */        ) /*!40100 DEFAULT CHARACTER SET utf8 */
56  EOT  EOT
57        );        );
58    
59          db_query(<<<EOT
60            CREATE TABLE {og_collections_pcpanel_join} (
61            pcpid int(11) NOT NULL,
62            pcpname varchar(32) NOT NULL,
63            PRIMARY KEY (pcpid)
64          ) /*!40100 DEFAULT CHARACTER SET utf8 */
65    EOT
66          );
67    
68        break;        break;
69    
# Line 65  EOT Line 74  EOT
74          pcpid integer(11) NOT NULL,          pcpid integer(11) NOT NULL,
75          pcpname varchar(32) NOT NULL,          pcpname varchar(32) NOT NULL,
76          grouptype varchar(32) NOT NULL DEFAULT 'default',          grouptype varchar(32) NOT NULL DEFAULT 'default',
77          version integer(4) NOT NULL DEFAULT 0,          version integer(4) NOT NULL DEFAULT 1,
78          PRIMARY KEY (did)          PRIMARY KEY (did)
79        )        )
80  EOT  EOT
# Line 106  EOT Line 115  EOT
115        )        )
116  EOT  EOT
117        );        );
118    
119          db_query(<<<EOT
120            CREATE TABLE {og_collections_pcpanel_join} (
121            pcpid integer(11) NOT NULL,
122            pcpname varchar(32) NOT NULL,
123            PRIMARY KEY (pcpid)
124          )
125    EOT
126          );
127    
128        break;        break;
129    }    }
# Line 130  function og_collections_update_5001() { Line 148  function og_collections_update_5001() {
148          PRIMARY KEY (opdid),          PRIMARY KEY (opdid),
149          KEY group_pcp_id (pcpid, grouptype),          KEY group_pcp_id (pcpid, grouptype),
150          KEY did_assoc (opdid, cur_pcpdid)          KEY did_assoc (opdid, cur_pcpdid)
151        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
152    
153        // no one SHOULD need this $ret[] = update_sql("ALTER TABLE {og_panels} DROP frompcpanel");        // no one SHOULD need this $ret[] = update_sql("ALTER TABLE {og_panels} DROP frompcpanel");
154        $ret[] = update_sql("ALTER TABLE {og_collections_pcpanel} MODIFY did INT(11)");        $ret[] = update_sql("ALTER TABLE {og_collections_pcpanel} MODIFY did INT(11)");
# Line 163  function og_collections_update_5001() { Line 181  function og_collections_update_5001() {
181  function og_collections_update_5002() {  function og_collections_update_5002() {
182    $ret = array();    $ret = array();
183    
184    // $ret[] = array(TRUE, t('NONE of these queries should have failed. If any did, PLEASE paste the text below into the OG Collections issues queue.'));    // $ret[] = array('success' => TRUE, 'query' => t('NONE of these queries should have failed. If any did, PLEASE paste the text below into the OG Collections issues queue.'));
185    $ret[] = update_sql(<<<EOT    $ret[] = update_sql(<<<EOT
186      CREATE TABLE {og_collections_versions} (      CREATE TABLE {og_collections_versions} (
187      grouptype varchar(32) NOT NULL,      grouptype varchar(32) NOT NULL,
# Line 174  function og_collections_update_5002() { Line 192  function og_collections_update_5002() {
192  EOT  EOT
193    );    );
194    
195      $ret[] = update_sql(<<<EOT
196        CREATE TABLE {og_collections_pcpanel_join} (
197        pcpid int(11) NOT NULL,
198        pcpname varchar(32) NOT NULL,
199        PRIMARY KEY (pcpid)
200      ) /*!40100 DEFAULT CHARACTER SET utf8 */
201    EOT
202        );
203    
204    // db_query_temporary("SELECT DISTINCT pcpid FROM {og_collections_pcpanel}", 'og_col_update');    // db_query_temporary("SELECT DISTINCT pcpid FROM {og_collections_pcpanel}", 'og_col_update');
205    $result = db_query("SELECT DISTINCT pcpid FROM {og_collections_pcpanel}");    $result = db_query("SELECT DISTINCT pcpid FROM {og_collections_pcpanel}");
206    $pcpids = array();    $pcpids = array();
# Line 182  EOT Line 209  EOT
209    }    }
210    
211    $ret[] = update_sql("UPDATE {og_collections_pcpanel} SET version = 0");    $ret[] = update_sql("UPDATE {og_collections_pcpanel} SET version = 0");
212    $ret[] = update_sql("ALTER TABLE {og_collections} ADD version int(4) NOT NULL DEFAULT 0 AFTER grouptype");    $ret[] = update_sql("ALTER TABLE {og_collections} ADD version int(4) NOT NULL DEFAULT 1 AFTER grouptype");
213    $ret[] = update_sql("ALTER TABLE {og_collections} ADD defaults text AFTER version");    $ret[] = update_sql("ALTER TABLE {og_collections} ADD defaults text AFTER version");
214    $ret[] = update_sql("ALTER TABLE {og_collections_pcpanel} ADD pcpname varchar(32) AFTER pcpid");    $ret[] = update_sql("ALTER TABLE {og_collections_pcpanel} ADD pcpname varchar(32) AFTER pcpid");
215    
# Line 191  EOT Line 218  EOT
218      $defaults = array();      $defaults = array();
219      $allcollections = db_query("SELECT * FROM {og_collections}");      $allcollections = db_query("SELECT * FROM {og_collections}");
220      while ($collectioncfg = db_fetch_array($allcollections)) {      while ($collectioncfg = db_fetch_array($allcollections)) {
221        foreach ($collectioncfg as $field => $value) {        foreach($collectioncfg as $field => $value) {
222          if (in_array($field, array('grouptype', 'defaults', 'version'))) {          if (in_array($field, array('grouptype', 'defaults', 'version'))) {
223            continue;            continue;
224          }          }
# Line 199  EOT Line 226  EOT
226          if (!empty($settings['usedef'])) {          if (!empty($settings['usedef'])) {
227            $defaults[$i][] = 'pcpanel_'. substr($field, 6);            $defaults[$i][] = 'pcpanel_'. substr($field, 6);
228          }          }
229          unset ($settings['usedef']);          $settings['enabled'] = $settings['active'];
230            unset($settings['usedef'], $settings['active'], $settings['version']); // the 'version' accidentally slipped in there occasionally; it's redundant data
231          // Bloody ugly hacks into the db abstraction layer, but update_sql() won't accept args like db_query()  
232          $query = "UPDATE {og_collections} SET $field = '%s' WHERE grouptype = '%s'";          // using modified version of update_sql() in order to allow character escaping; necessary for serialized values
233          $args = array(serialize($settings), $collectioncfg['grouptype']);          $ret[] = _update_sql("UPDATE {og_collections} SET $field = '%s' WHERE grouptype = '%s'", serialize($settings), $collectioncfg['grouptype']);
         _db_query_callback($args, TRUE);  
         $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);  
         $ret[] = update_sql($query);  
         unset($query, $args);  
234        }        }
235    
236        if ($collectioncfg['grouptype'] != 'default') { // default group shouldn't have anything in its defaults field, although it doesn't really matter        if ($collectioncfg['grouptype'] != 'default') { // default group shouldn't have anything in its defaults field, although it doesn't really matter
237          // same ugly db abstraction hack          $ret[] = _update_sql("UPDATE {og_collections} SET defaults = '%s' WHERE grouptype = '%s'", serialize($defaults[$i]), $collectioncfg['grouptype']);
         $query = "UPDATE {og_collections} SET defaults = '%s' WHERE grouptype = '%s'";  
         $args = array(serialize($defaults[$i]), $collectioncfg['grouptype']);  
         _db_query_callback($args, TRUE);  
         $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);  
         $ret[] = update_sql($query);  
         unset($query, $args);  
238        }        }
239        $i++;        $i++;
240      }      }
# Line 229  EOT Line 246  EOT
246      }      }
247      $ret[] = update_sql(substr($sql, 0, -2));      $ret[] = update_sql(substr($sql, 0, -2));
248    }    }
249      $forjoins = db_query("SELECT DISTINCT pcpid, pcpname FROM {og_collections_pcpanel}");
250      $joins_data = array();
251      $escape_chars = array();
252      while ($row = db_fetch_array($forjoins)) {
253        $joins_data['pcpid'][] = $row['pcpid'];
254        $joins_data['pcpname'][] = $row['pcpname'];
255        $escape_chars['pcpid'][] = "%d";
256        $escape_chars['pcpname'][] = "'%s'";
257      }
258    
259      $ret[] = _update_sql("INSERT INTO {og_collections_pcpanel_join} (pcpid, pcpname) VALUES (". implode(', ', $escape_chars['pcpid']) ."), (". implode(', ', $escape_chars['pcpname']) .")", array_merge($joins_data['pcpid'], $joins_data['pcpname']));
260    
261    return $ret;    return $ret;
262  }  }
# Line 238  function og_collections_uninstall() { Line 266  function og_collections_uninstall() {
266    db_query('DROP TABLE {og_collections}');    db_query('DROP TABLE {og_collections}');
267    db_query('DROP TABLE {og_collections_control}');    db_query('DROP TABLE {og_collections_control}');
268    db_query('DROP TABLE {og_collections_versions}');    db_query('DROP TABLE {og_collections_versions}');
269      db_query('DROP TABLE {og_collections_pcpanel_join}');
270    
271    // Delete variables    // Delete variables
272    $variables = array('og_collections_settings');    $variables = array('og_collections_settings');
# Line 254  function og_collections_enable() { Line 283  function og_collections_enable() {
283      drupal_set_message(t('OG Collections has been installed. You can begin configuring your Group Collections at the !link administrative menu.', array('!link' => l(t('OG Collections'), 'admin/og/og_collections'))));      drupal_set_message(t('OG Collections has been installed. You can begin configuring your Group Collections at the !link administrative menu.', array('!link' => l(t('OG Collections'), 'admin/og/og_collections'))));
284      drupal_set_message(t('Some significant changes to the og_collections schema have been made in this update. I have tested them to the best of my ability, but og_collections is inherently complex and well beyond my ability to exhaustively test alone. Given these facts, you are STRONGLY advised to backup your database before running !update', l(t('update.php.'), 'update.php')));      drupal_set_message(t('Some significant changes to the og_collections schema have been made in this update. I have tested them to the best of my ability, but og_collections is inherently complex and well beyond my ability to exhaustively test alone. Given these facts, you are STRONGLY advised to backup your database before running !update', l(t('update.php.'), 'update.php')));
285  }  }
286    
287    /**
288     * Smarter implementation of update_sql() that allows for args to be passed
289     * through the normal db_query escaping functions. So, mostly nicked from db_query()
290     *
291     */
292    function _update_sql($sql) {
293      $args = func_get_args();
294      array_shift($args);
295      if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax
296        $args = $args[0];
297      }
298      $result = db_query($sql, $args);
299      _db_query_callback($args, TRUE);
300      $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $sql);
301      return array('success' => $result !== FALSE, 'query' => check_plain($query));
302    }

Legend:
Removed from v.1.2.2.4  
changed lines
  Added in v.1.2.2.5

  ViewVC Help
Powered by ViewVC 1.1.2