/[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.5, Mon Apr 7 10:16:52 2008 UTC revision 1.2.2.6, Sat Apr 12 04:35:07 2008 UTC
# Line 178  function og_collections_update_5001() { Line 178  function og_collections_update_5001() {
178    return $ret;    return $ret;
179  }  }
180    
181  function og_collections_update_5002() {  /**
182    $ret = array();   * Implementation of hook_enable()
183     *
184     */
185    function og_collections_enable() {
186        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'))));
187        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')));
188    }
189    
190    // $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.'));  function og_collections_update_5002() {
191    $ret[] = update_sql(<<<EOT    if (module_exists('og_blueprints')) {
192      CREATE TABLE {og_collections_versions} (      $bp_fields = array(
193      grouptype varchar(32) NOT NULL,        'bpid' => '%d',
194      vid int(4) NOT NULL DEFAULT 0,        'bid' => '%d',
195      data mediumblob,        'vid' => '%d',
196      PRIMARY KEY (grouptype, vid)        'bpname' => "'%s'",
197    ) /*!40100 DEFAULT CHARACTER SET utf8 */        'did' => '%d',
198  EOT        'linked' => '%d',
199    );        'enabled' => '%d',
200          'published' => '%d',
201    $ret[] = update_sql(<<<EOT        'default_page' => '%d',
202      CREATE TABLE {og_collections_pcpanel_join} (        'page_title' => "'%s'",
203      pcpid int(11) NOT NULL,        'path' => "'%s'",
204      pcpname varchar(32) NOT NULL,        'weight' => '%d'
205      PRIMARY KEY (pcpid)      );
206    ) /*!40100 DEFAULT CHARACTER SET utf8 */      $result = db_query("SELECT * FROM {og_collections}");
207  EOT      while ($row = db_fetch_array($result)) {
208      );        if ($row['grouptype'] != 'default') {
209            $bid = db_next_id('{og_bundle}_bid');
210    // db_query_temporary("SELECT DISTINCT pcpid FROM {og_collections_pcpanel}", 'og_col_update');          db_query("INSERT INTO {og_bundle} (grouptype, bid) VALUES ('%s', %d)", $row['grouptype'], $bid);
211    $result = db_query("SELECT DISTINCT pcpid FROM {og_collections_pcpanel}");          db_query("INSERT INTO {og_bundle_revision} (bid) VALUES (%d)", $bid);
212    $pcpids = array();          $vid = db_result(db_query("SELECT vid FROM {og_bundle_revision} ORDER BY vid DESC LIMIT 1"));
213    while ($row = db_fetch_array($result)) {        }
214      $pcpids[] = $row['pcpid'];        else {
215    }          $bid = $vid = 1;
216          }
217    $ret[] = update_sql("UPDATE {og_collections_pcpanel} SET version = 0");        db_query("UPDATE {og_bundle} SET vid = %d WHERE bid = %d", $vid, $bid);
218    $ret[] = update_sql("ALTER TABLE {og_collections} ADD version int(4) NOT NULL DEFAULT 1 AFTER grouptype");  
219    $ret[] = update_sql("ALTER TABLE {og_collections} ADD defaults text AFTER version");        foreach ($row as $field => $value) {
   $ret[] = update_sql("ALTER TABLE {og_collections_pcpanel} ADD pcpname varchar(32) AFTER pcpid");  
   
   if (!empty($pcpids)) {  
     $i = 1000; // just a surefire means of differentiating the arrays later on  
     $defaults = array();  
     $allcollections = db_query("SELECT * FROM {og_collections}");  
     while ($collectioncfg = db_fetch_array($allcollections)) {  
       foreach($collectioncfg as $field => $value) {  
220          if (in_array($field, array('grouptype', 'defaults', 'version'))) {          if (in_array($field, array('grouptype', 'defaults', 'version'))) {
221            continue;            continue;
222          }          }
223          $settings = unserialize($value);          $settings = unserialize($value);
224          if (!empty($settings['usedef'])) {          $settings['bpid'] = (int) substr($field, 6);
225            $defaults[$i][] = 'pcpanel_'. substr($field, 6);          $settings['bpname'] = 'blueprint_'. $settings['bpid'];
         }  
226          $settings['enabled'] = $settings['active'];          $settings['enabled'] = $settings['active'];
227          unset($settings['usedef'], $settings['active'], $settings['version']); // the 'version' accidentally slipped in there occasionally; it's redundant data          $settings['linked'] = $settings['usedef'];
228            $settings['bid'] = $bid;
229            $settings['vid'] = $vid;
230    
231          // using modified version of update_sql() in order to allow character escaping; necessary for serialized values          foreach ($bp_fields as $field => $value) {
232          $ret[] = _update_sql("UPDATE {og_collections} SET $field = '%s' WHERE grouptype = '%s'", serialize($settings), $collectioncfg['grouptype']);            $f[] = $field;
233        }            $q[] = $value;
234              $v[] = $settings[$field];
235        if ($collectioncfg['grouptype'] != 'default') { // default group shouldn't have anything in its defaults field, although it doesn't really matter          }
236          $ret[] = _update_sql("UPDATE {og_collections} SET defaults = '%s' WHERE grouptype = '%s'", serialize($defaults[$i]), $collectioncfg['grouptype']);          db_query("INSERT INTO {og_blueprint} (". implode(', ', $f) .") VALUES (". implode(', ', $q) .")", $v);
237            unset ($f, $q, $v);
238        }        }
       $i++;  
239      }      }
240        $bpid_num = db_result(db_query("SELECT DISTINCT bpid FROM {og_blueprint} ORDER BY bpid DESC LIMIT 1"));
241      $sql = "ALTER TABLE {og_collections} ";      while ($i++ < $bpid_num) {
242      foreach ($pcpids as $pcpid) {        db_next_id("{og_blueprint}_bpid");
       $ret[] = update_sql("UPDATE {og_collections_pcpanel} SET pcpname = 'pcpanel_$pcpid' WHERE pcpid = $pcpid");  
       $sql .= "CHANGE pcpid_$pcpid pcpanel_$pcpid longtext, ";  
243      }      }
     $ret[] = update_sql(substr($sql, 0, -2));  
244    }    }
   $forjoins = db_query("SELECT DISTINCT pcpid, pcpname FROM {og_collections_pcpanel}");  
   $joins_data = array();  
   $escape_chars = array();  
   while ($row = db_fetch_array($forjoins)) {  
     $joins_data['pcpid'][] = $row['pcpid'];  
     $joins_data['pcpname'][] = $row['pcpname'];  
     $escape_chars['pcpid'][] = "%d";  
     $escape_chars['pcpname'][] = "'%s'";  
   }  
   
   $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']));  
   
   return $ret;  
 }  
   
 function og_collections_uninstall() {  
   db_query('DROP TABLE {og_collections_pcpanel}');  
   db_query('DROP TABLE {og_collections}');  
   db_query('DROP TABLE {og_collections_control}');  
   db_query('DROP TABLE {og_collections_versions}');  
   db_query('DROP TABLE {og_collections_pcpanel_join}');  
   
   // Delete variables  
   $variables = array('og_collections_settings');  
   foreach ($variables as $variable) {  
     variable_del($variable);  
   }  
 }  
   
 /**  
  * Implementation of hook_enable()  
  *  
  */  
 function og_collections_enable() {  
     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('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')));  
245  }  }
246    
247  /**  /**
# Line 300  function _update_sql($sql) { Line 260  function _update_sql($sql) {
260    $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $sql);    $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $sql);
261    return array('success' => $result !== FALSE, 'query' => check_plain($query));    return array('success' => $result !== FALSE, 'query' => check_plain($query));
262  }  }
263    
264    function og_collections_uninstall() {
265      db_query('DROP TABLE IF EXISTS {og_collections_pcpanel}');
266      db_query('DROP TABLE IF EXISTS {og_collections}');
267      db_query('DROP TABLE IF EXISTS {og_collections_control}');
268      db_query('DROP TABLE IF EXISTS {og_collections_versions}');
269      db_query('DROP TABLE IF EXISTS {og_collections_pcpanel_join}');
270      db_query("DELETE FROM {sequences} WHERE name = '{og_collections_pcpanel}_pcpid'");
271    
272      // Delete variables
273      $variables = array('og_collections_settings');
274      foreach ($variables as $variable) {
275        variable_del($variable);
276      }
277    }

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

  ViewVC Help
Powered by ViewVC 1.1.2