/[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.3, Mon Apr 7 00:20:00 2008 UTC revision 1.2.2.4, Mon Apr 7 02:25:27 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: og_collections.install,v 1.2.2.2 2008/04/06 20:43:45 sdboyer Exp $  // $Id: og_collections.install,v 1.2.2.3 2008/04/07 00:20:00 sdboyer Exp $
3    
4  function og_collections_install() {  function og_collections_install() {
5    switch ($GLOBALS['db_type']) {    switch ($GLOBALS['db_type']) {
# Line 162  function og_collections_update_5001() { Line 162  function og_collections_update_5001() {
162    
163  function og_collections_update_5002() {  function og_collections_update_5002() {
164    $ret = array();    $ret = array();
165    
166      // $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.'));
167    $ret[] = update_sql(<<<EOT    $ret[] = update_sql(<<<EOT
168      CREATE TABLE {og_collections_versions} (      CREATE TABLE {og_collections_versions} (
169      grouptype varchar(32) NOT NULL,      grouptype varchar(32) NOT NULL,
# Line 171  function og_collections_update_5002() { Line 173  function og_collections_update_5002() {
173    ) /*!40100 DEFAULT CHARACTER SET utf8 */    ) /*!40100 DEFAULT CHARACTER SET utf8 */
174  EOT  EOT
175    );    );
176    
177    // 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');
178    $result = db_query("SELECT DISTINCT pcpid FROM {og_collections_pcpanel}");    $result = db_query("SELECT DISTINCT pcpid FROM {og_collections_pcpanel}");
179    $pcpids = array();    $pcpids = array();
180    while ($row = db_fetch_array($result)) {    while ($row = db_fetch_array($result)) {
181      $pcpids[] = $row['pcpid'];      $pcpids[] = $row['pcpid'];
182    }    }
183    
184      $ret[] = update_sql("UPDATE {og_collections_pcpanel} SET version = 0");
185    $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 0 AFTER grouptype");
186    $ret[] = update_sql("ALTER TABLE {og_collections} ADD defaults text AFTER version");    $ret[] = update_sql("ALTER TABLE {og_collections} ADD defaults text AFTER version");
187    $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");
# Line 187  EOT Line 191  EOT
191      $defaults = array();      $defaults = array();
192      $allcollections = db_query("SELECT * FROM {og_collections}");      $allcollections = db_query("SELECT * FROM {og_collections}");
193      while ($collectioncfg = db_fetch_array($allcollections)) {      while ($collectioncfg = db_fetch_array($allcollections)) {
       $grouptype = $collectioncfg['grouptype'];  
194        foreach ($collectioncfg as $field => $value) {        foreach ($collectioncfg as $field => $value) {
195          if (in_array($field, array('grouptype', 'defaults', 'version'))) {          if (in_array($field, array('grouptype', 'defaults', 'version'))) {
196            continue;            continue;
# Line 197  EOT Line 200  EOT
200            $defaults[$i][] = 'pcpanel_'. substr($field, 6);            $defaults[$i][] = 'pcpanel_'. substr($field, 6);
201          }          }
202          unset ($settings['usedef']);          unset ($settings['usedef']);
203          $serialized_settings = serialize($settings);  
204          $ret[] = update_sql(<<<EOT          // Bloody ugly hacks into the db abstraction layer, but update_sql() won't accept args like db_query()
205          UPDATE {og_collections} SET $field = '$serialized_settings' WHERE grouptype = '$grouptype'          $query = "UPDATE {og_collections} SET $field = '%s' WHERE grouptype = '%s'";
206  EOT          $args = array(serialize($settings), $collectioncfg['grouptype']);
207          );          _db_query_callback($args, TRUE);
208            $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);
209            $ret[] = update_sql($query);
210            unset($query, $args);
211        }        }
212    
213        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
214          $groupdefaults = serialize($defaults[$i]);          // same ugly db abstraction hack
215          $ret[] = update_sql(<<<EOT          $query = "UPDATE {og_collections} SET defaults = '%s' WHERE grouptype = '%s'";
216          UPDATE {og_collections} SET defaults = '$groupdefaults' WHERE grouptype = '$grouptype'          $args = array(serialize($defaults[$i]), $collectioncfg['grouptype']);
217  EOT          _db_query_callback($args, TRUE);
218          );          $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);
219            $ret[] = update_sql($query);
220            unset($query, $args);
221        }        }
222        $i++;        $i++;
223      }      }
224    
225      $sql = "ALTER TABLE {og_collections} ";      $sql = "ALTER TABLE {og_collections} ";
226      foreach ($pcpids as $pcpid) {      foreach ($pcpids as $pcpid) {
227        $ret[] = update_sql("UPDATE {og_collections_pcpanel} SET pcpname = 'pcpanel_$pcpid' WHERE pcpid = $pcpid");        $ret[] = update_sql("UPDATE {og_collections_pcpanel} SET pcpname = 'pcpanel_$pcpid' WHERE pcpid = $pcpid");
# Line 242  function og_collections_uninstall() { Line 252  function og_collections_uninstall() {
252   */   */
253  function og_collections_enable() {  function og_collections_enable() {
254      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'))));
255        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')));
256  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.2