[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/project/release/ -> project_release.install (source)

   1  <?php
   2  // $Id: project_release.install,v 1.30 2010/01/30 02:33:40 dww Exp $
   3  
   4  function project_release_install() {
   5    // Create the database tables.
   6    drupal_install_schema('project_release');
   7  
   8    // Make this module heavier than the default module weight.
   9    db_query("UPDATE {system} SET weight = %d WHERE name = 'project_release'", 2);
  10  }
  11  
  12  /**
  13   * Implementation of hook_uninstall().
  14   */
  15  function project_release_uninstall() {
  16    // Drop database tables.
  17    drupal_uninstall_schema('project_release');
  18  
  19    $variables = array(
  20      'project_release_active_compatibility_tids',
  21      'project_release_api_vocabulary',
  22      'project_release_browse_versions',
  23      'project_release_default_version_format',
  24      'project_release_directory',
  25      'project_release_download_base',
  26      'project_release_overview',
  27      'project_release_unmoderate',
  28      'project_release_file_extensions',
  29      'project_release_version_extra_weights',
  30    );
  31    foreach ($variables as $variable) {
  32      variable_del($variable);
  33    }
  34  }
  35  
  36  /**
  37   * Implementation of hook_schema().
  38   */
  39  function project_release_schema() {
  40    $schema['project_release_nodes'] = array(
  41      'description' => 'The base table for project_project nodes.',
  42      'fields' => array(
  43        'nid' => array(
  44          'description' => 'Primary Key: The {node}.nid of the project_release node.',
  45          'type' => 'int',
  46          'unsigned' => TRUE,
  47          'not null' => TRUE,
  48          'default' => 0,
  49        ),
  50        'pid' => array(
  51          'description' => 'The {project_projects}.nid of the project_project node with which the project_release node is associated.',
  52          'type' => 'int',
  53          'unsigned' => TRUE,
  54          'not null' => TRUE,
  55          'default' => 0,
  56        ),
  57        'version' => array(
  58          'description' => 'A string containing the full version of a release. The format of this string for a given project is dictated by {project_release_projects}.version_format.',
  59          'type' => 'varchar',
  60          'length' => 255,
  61          'not null' => TRUE,
  62          'default' => '',
  63        ),
  64        'tag' => array(
  65          'description' => 'The name of a CVS branch or tag on which a release is based.',
  66          'type' => 'varchar',
  67          'length' => 255,
  68          'not null' => TRUE,
  69          'default' => '',
  70        ),
  71        'rebuild' => array(
  72          'description' => 'A flag indicating whether or not the file associated with a release should be rebuilt periodically. For official releases this should be 0, for development snapshots it should be 1.',
  73          'type' => 'int',
  74          'size' => 'tiny',
  75          'unsigned' => FALSE,
  76          'not null' => FALSE,
  77          'default' => 0,
  78        ),
  79        'version_major' => array(
  80          'description' => 'The major version number of a release.',
  81          'type' => 'int',
  82          'unsigned' => FALSE,
  83          'not null' => FALSE,
  84          'default' => NULL,
  85        ),
  86        'version_minor' => array(
  87          'description' => 'The minor version number of a release.',
  88          'type' => 'int',
  89          'unsigned' => FALSE,
  90          'not null' => FALSE,
  91          'default' => NULL,
  92        ),
  93        'version_patch' => array(
  94          'description' => 'The patch level version number of a release.',
  95          'type' => 'int',
  96          'unsigned' => FALSE,
  97          'not null' => FALSE,
  98          'default' => NULL,
  99        ),
 100        'version_extra' => array(
 101          'description' => 'A text string that can be used to provide additional information about a release.  Ex: BETA',
 102          'type' => 'varchar',
 103          'length' => 255,
 104          'not null' => FALSE,
 105          'default' => NULL,
 106        ),
 107        'version_extra_weight' => array(
 108          'description' => 'Numeric code for ordering releases that define "version_extra".',
 109          'type' => 'int',
 110          'not null' => TRUE,
 111          'default' => 0,
 112        ),
 113        'version_extra_delta' => array(
 114          'description' => 'The first span of digits found in version_extra. This is needed because we cannot natural sort natively without a stored procedure.',
 115          'type' => 'int',
 116          'not null' => TRUE,
 117          'default' => 0,
 118        ),
 119        'version_api_tid' => array(
 120          'description' => 'The denormalized {term_node}.tid of the API compatibility term for this release, or 0 if the release has no such term.',
 121          'type' => 'int',
 122          'unsigned' => TRUE,
 123          'not null' => FALSE,
 124          'default' => NULL,
 125        ),
 126        'security_update' => array(
 127          'description' => 'Denormalized flag to record if this release has the "project_release_security_update_tid" taxonomy term set or not',
 128          'type' => 'int',
 129          'size' => 'tiny',
 130          'unsigned' => TRUE,
 131          'not null' => TRUE,
 132          'default' => 0,
 133        ),
 134        'update_status' => array(
 135          'description' => 'Denormalized flag to record the update status for this release. Allowed values: PROJECT_RELEASE_UPDATE_STATUS_CURRENT (0), PROJECT_RELEASE_UPDATE_STATUS_NOT_CURRENT (1), PROJECT_RELEASE_UPDATE_STATUS_NOT_SECURE (2)',
 136          'type' => 'int',
 137          'size' => 'tiny',
 138          'not null' => TRUE,
 139          'default' => 0,
 140        ),
 141      ),
 142      'primary key' => array('nid'),
 143      'indexes' => array(
 144        'project_releases_pid' => array('pid')
 145      ),
 146    );
 147  
 148    $schema['project_release_file'] = array(
 149      'description' => 'Stores information about files attached to release nodes.',
 150      'fields' => array(
 151        'fid' => array(
 152          'description' => 'Foreign Key: {files}.fid.',
 153          'type' => 'int',
 154          'unsigned' => TRUE,
 155          'not null' => TRUE,
 156          'default' => 0,
 157        ),
 158        'nid' => array(
 159          'description' => 'Foreign Key: {project_release_nodes}.nid.',
 160          'type' => 'int',
 161          'unsigned' => TRUE,
 162          'not null' => TRUE,
 163          'default' => 0,
 164        ),
 165        'filehash' => array(
 166          'description' => 'An MD5 hash of the file.',
 167          'type' => 'varchar',
 168          'length' => 32,
 169          'not null' => TRUE,
 170          'default' => '',
 171        ),
 172      ),
 173      'primary key' => array('fid'),
 174      'indexes' => array('nid' => array('nid')),
 175    );
 176  
 177    $schema['project_release_projects'] = array(
 178      'description' => 'Table used to store release specific information about projects.',
 179      'fields' => array(
 180        'nid' => array(
 181          'description' => 'Primary Key: The {project_projects}.nid of the project_project node.',
 182          'type' => 'int',
 183          'unsigned' => TRUE,
 184          'not null' => TRUE,
 185          'default' => 0,
 186        ),
 187        'releases' => array(
 188          'description' => 'A flag indicating whether or not releases are enabled for a project.',
 189          'type' => 'int',
 190          'size' => 'tiny',
 191          'unsigned' => FALSE,
 192          'not null' => TRUE,
 193          'default' => 1,
 194        ),
 195        'version_format' => array(
 196          'description' => 'A string used to designate the format of the {project_release_nodes}.version field for releases of a project.',
 197          'type' => 'varchar',
 198          'length' => 255,
 199          'not null' => TRUE,
 200          'default' => '',
 201        ),
 202      ),
 203      'primary key' => array('nid'),
 204      'indexes' => array(
 205        'project_release_projects_releases' => array('releases')
 206      ),
 207    );
 208  
 209    $schema['project_release_supported_versions'] = array(
 210      'description' => 'Table used to store information about which major versions of a project are supported and/or recommended.',
 211      'fields' => array(
 212        'nid' => array(
 213          'description' => 'Primary Key: The {project_projects}.nid of the project_project node.',
 214          'type' => 'int',
 215          'unsigned' => TRUE,
 216          'not null' => TRUE,
 217          'default' => 0,
 218        ),
 219        'tid' => array(
 220          'description' => 'Primary Key: The {term_data}.tid of the API compatability version associated with a major version of a project.',
 221          'type' => 'int',
 222          'unsigned' => TRUE,
 223          'not null' => TRUE,
 224          'default' => 0,
 225        ),
 226        'major' => array(
 227          'description' => 'Primary Key: The {project_release_nodes}.version_major of a release node.',
 228          'type' => 'int',
 229          'unsigned' => TRUE,
 230          'not null' => TRUE,
 231          'default' => 0,
 232        ),
 233        'supported' => array(
 234          'description' => 'A flag to indicate whether or not a given major version of a project is supported.',
 235          'type' => 'int',
 236          'size' => 'tiny',
 237          'unsigned' => TRUE,
 238          'not null' => TRUE,
 239          'default' => 1,
 240        ),
 241        'recommended' => array(
 242          'description' => 'A flag to indicate whether or not a given major version of a project is recommended.',
 243          'type' => 'int',
 244          'size' => 'tiny',
 245          'unsigned' => TRUE,
 246          'not null' => TRUE,
 247          'default' => 0,
 248        ),
 249        'snapshot' => array(
 250          'description' => 'A flag to indicate whether or not snapshot releases of a major version of a project should be shown in the release download table.',
 251          'type' => 'int',
 252          'size' => 'tiny',
 253          'unsigned' => TRUE,
 254          'not null' => TRUE,
 255          'default' => 0,
 256        ),
 257        'recommended_release' => array(
 258          'description' => 'The {project_release_nodes}.nid of the recommended release node for this API tid and major version (the latest release without any "extra" version info such as "alpha1").',
 259          'type' => 'int',
 260          'unsigned' => TRUE,
 261          'not null' => TRUE,
 262          'default' => 0,
 263        ),
 264        'latest_release' => array(
 265          'description' => 'The {project_release_nodes}.nid of the latest release node for this API tid and major version (even if it has "extra" version info such as "alpha1").',
 266          'type' => 'int',
 267          'unsigned' => TRUE,
 268          'not null' => TRUE,
 269          'default' => 0,
 270        ),
 271        'latest_security_release' => array(
 272          'description' => 'The {project_release_nodes}.nid of the latest release node marked as a "security update" for this API tid and major version.',
 273          'type' => 'int',
 274          'unsigned' => TRUE,
 275          'not null' => TRUE,
 276          'default' => 0,
 277        ),
 278      ),
 279      'primary key' => array('nid', 'tid', 'major'),
 280    );
 281  
 282    $schema['project_release_package_errors'] = array(
 283      'description' => 'Table used to store error messages generated by the scripts that package project_release nodes into tarballs.',
 284      'fields' => array(
 285        'nid' => array(
 286          'description' => 'Primary Key: The {node}.nid of the project_release node.',
 287          'type' => 'int',
 288          'unsigned' => TRUE,
 289          'not null' => TRUE,
 290          'default' => 0,
 291        ),
 292        'messages' => array(
 293          'description' => 'The text of any error messages created by the packaging scripts.',
 294          'type' => 'text',
 295          'not null' => FALSE,
 296        )
 297      ),
 298      'primary key' => array('nid'),
 299    );
 300  
 301    $schema['cache_project_release'] = array(
 302      'description' => 'Cache table used to store the project release download tables.',
 303      'fields' => array(
 304        'cid' => array(
 305          'description' => 'Primary Key: Unique cache ID.',
 306          'type' => 'varchar',
 307          'length' => 255,
 308          'not null' => TRUE,
 309          'default' => '',
 310        ),
 311        'data' => array(
 312          'description' => 'A collection of data to cache.',
 313          'type' => 'blob',
 314          'not null' => FALSE,
 315          'size' => 'big',
 316        ),
 317        'expire' => array(
 318          'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
 319          'type' => 'int',
 320          'not null' => TRUE,
 321          'default' => 0,
 322        ),
 323        'created' => array(
 324          'description' => 'A Unix timestamp indicating when the cache entry was created.',
 325          'type' => 'int',
 326          'not null' => TRUE,
 327          'default' => 0,
 328        ),
 329        'headers' => array(
 330          'description' => 'Any custom HTTP headers to be added to cached data.',
 331          'type' => 'text',
 332          'not null' => FALSE,
 333        ),
 334        'serialized' => array(
 335          'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
 336          'type' => 'int',
 337          'size' => 'small',
 338          'not null' => TRUE,
 339          'default' => 0
 340        ),
 341      ),
 342      'primary key' => array('cid'),
 343      'indexes' => array(
 344        'expire' => array('expire')
 345      ),
 346    );
 347    return $schema;
 348  }
 349  
 350  /**
 351   * Populate the {project_release_nodes}.security_update field.
 352   *
 353   * @param $ret
 354   *   Reference to an array for hook_update_N() return values.
 355   */
 356  function _project_release_check_security_updates(&$ret) {
 357    $security_update_tid = variable_get('project_release_security_update_tid', 0);
 358    if (!empty($security_update_tid)) {
 359      $ret[] = update_sql("UPDATE {project_release_nodes} SET security_update = (SELECT tn.tid IS NOT NULL FROM node n LEFT JOIN term_node tn ON n.vid = tn.vid AND tn.tid = $security_update_tid WHERE n.nid = {project_release_nodes}.nid)");
 360    }
 361  }
 362  
 363  /**
 364   * Populate the {project_release_nodes}.version_extra_weight field.
 365   *
 366   * @param $ret
 367   *   Reference to an array for hook_update_N() return values.
 368   */
 369  function _project_release_update_version_extra_weights(&$ret) {
 370    $weights = project_release_get_version_extra_weight_map();
 371    foreach ($weights as $prefix => $weight) {
 372      if ($prefix == 'NULL') {
 373        $ret[] = update_sql("UPDATE {project_release_nodes} SET version_extra_weight = $weight WHERE version_extra IS NULL");
 374      }
 375      else {
 376        $ret[] = update_sql("UPDATE {project_release_nodes} SET version_extra_weight = $weight WHERE LOWER(version_extra) LIKE '" . $prefix . "%'");
 377      }
 378    }
 379  }
 380  
 381  /**
 382   * Add the 'serialized' field to the {cache_project_release} table.
 383   */
 384  function project_release_update_6000() {
 385    $ret = array();
 386    $spec = array(
 387      'type' => 'int',
 388      'size' => 'small',
 389      'default' => 0,
 390      'not null' => TRUE,
 391    );
 392    db_add_field($ret, 'cache_project_release', 'serialized', $spec);
 393    return $ret;
 394  }
 395  
 396  /**
 397   * Add {project_release_file}.
 398   */
 399  function project_release_update_6001() {
 400    $ret = array();
 401    $schema = project_release_schema();
 402    db_create_table($ret, 'project_release_file', $schema['project_release_file']);
 403    return $ret;
 404  }
 405  
 406  /**
 407   * Convert release file attachments to use core's file API.
 408   */
 409  function project_release_update_6002() {
 410    // This determines how many issue nodes will be processed in each
 411    // batch run. A reasonable default has been chosen, but you may
 412    // want to tweak depending on your setup.
 413    $limit = 100;
 414  
 415    // Multi-part update
 416    if (!isset($_SESSION['project_release_update_6002'])) {
 417      $_SESSION['project_release_update_6002'] = 0;
 418      $_SESSION['project_release_update_6002_max'] = db_result(db_query("SELECT COUNT(prn.nid) FROM {project_release_nodes} prn INNER JOIN {node} n ON prn.nid = n.nid WHERE prn.file_path <> ''"));
 419    }
 420  
 421    // Pull the next batch of files.
 422    $files = db_query_range("SELECT prn.*, n.uid FROM {project_release_nodes} prn INNER JOIN {node} n ON prn.nid = n.nid WHERE prn.file_path <> '' ORDER BY prn.nid", $_SESSION['project_release_update_6002'], $limit);
 423  
 424    // Loop through each file.
 425    while ($file = db_fetch_object($files)) {
 426      // Make sure file is still there.
 427      if (file_exists($file->file_path)) {
 428        $filename = basename($file->file_path);
 429        $filesize = filesize(file_create_path($file->file_path));
 430        $filemime = file_get_mimetype($filename);
 431        db_query("INSERT INTO {files} (uid, filename, filepath, filemime, filesize, status, timestamp) VALUES (%d, '%s', '%s', '%s', '%s', %d, %d)", $file->uid, $filename, $file->file_path, $filemime, $filesize, FILE_STATUS_PERMANENT, $file->file_date);
 432        $fid = db_last_insert_id('files', 'fid');
 433        db_query("INSERT INTO {project_release_file} (fid, nid, filehash) VALUES (%d, %d,'%s')", $fid, $file->nid, $file->file_hash);
 434      }
 435      $_SESSION['project_release_update_6002']++;
 436    }
 437  
 438    if ($_SESSION['project_release_update_6002'] >= $_SESSION['project_release_update_6002_max']) {
 439      $count = $_SESSION['project_release_update_6002_max'];
 440      unset($_SESSION['project_release_update_6002']);
 441      unset($_SESSION['project_release_update_6002_max']);
 442      return array(array('success' => TRUE, 'query' => t('Converted release file attachments for @count releases', array('@count' => $count))));
 443    }
 444    return array('#finished' => $_SESSION['project_release_update_6002'] / $_SESSION['project_release_update_6002_max']);
 445  
 446  }
 447  
 448  /**
 449   * Drop unused fields from {project_release_nodes}.
 450   */
 451  function project_release_update_6003() {
 452    $ret = array();
 453    db_drop_field($ret, 'project_release_nodes', 'file_path');
 454    db_drop_field($ret, 'project_release_nodes', 'file_date');
 455    db_drop_field($ret, 'project_release_nodes', 'file_hash');
 456    return $ret;
 457  }
 458  
 459  /**
 460   * Add new columns to {project_release_supported_versions}.
 461   */
 462  function project_release_update_6004() {
 463    $ret = array('#finished' => 0);
 464    if (!isset($_SESSION['project_release_update_6004'])) {
 465      $spec = array('type' => 'int', 'unsigned' => TRUE, 'default' => NULL, 'not null' => FALSE);
 466      db_add_field($ret, 'project_release_supported_versions', 'recommended_release', $spec);
 467      db_add_field($ret, 'project_release_supported_versions', 'latest_release', $spec);
 468      $_SESSION['project_release_update_6004'] = 0;
 469      $_SESSION['project_release_update_6004_max'] = db_result(db_query("SELECT COUNT(*) FROM {project_release_supported_versions}"));
 470    }
 471  
 472    // Number of rows to convert per batch.
 473    $limit = 20;
 474    while ($limit-- && $item = db_fetch_array(db_query_range("SELECT * FROM {project_release_supported_versions} WHERE latest_release IS NULL", 0, 1))) {
 475      // We have a branch we haven't processed yet (latest_release is still
 476      // NULL), so we invoke project_release_check_supported_versions() to
 477      // run some queries to determine the recommended and latest releases on
 478      // that branch. Normally, it updates {project_release_supported_versions}
 479      // with this data in which case it returns TRUE. However, if it returns
 480      // FALSE, it means we didn't find any releases on that branch, and it
 481      // didn't touch the table. In that case, we need to update the table
 482      // ourselves for this branch to mark the new fields as 0 (not NULL) so
 483      // that we don't check this branch again.
 484      if (!project_release_check_supported_versions($item['nid'], $item['tid'], $item['major'], FALSE)) {
 485        db_query("UPDATE {project_release_supported_versions} SET recommended_release = %d, latest_release = %d WHERE nid = %d AND tid = %d AND major = %d", 0, 0, $item['nid'], $item['tid'], $item['major']);
 486      }
 487      $_SESSION['project_release_update_6004']++;
 488    }
 489  
 490    if ($_SESSION['project_release_update_6004'] >= $_SESSION['project_release_update_6004_max']) {
 491      // We're done.  Set our new columns to default to 0 from here on out.
 492      $ret[] = update_sql("ALTER TABLE {project_release_supported_versions} ALTER COLUMN recommended_release SET DEFAULT 0");
 493      $ret[] = update_sql("ALTER TABLE {project_release_supported_versions} ALTER COLUMN latest_release SET DEFAULT 0");
 494      unset($_SESSION['project_release_update_6004']);
 495      unset($_SESSION['project_release_update_6004_max']);
 496      $ret['#finished'] = 1;
 497    }
 498    else {
 499      $ret['#finished'] = $_SESSION['project_release_update_6004'] / $_SESSION['project_release_update_6004_max'];
 500    }
 501    return $ret;
 502  }
 503  
 504  /**
 505   * Add the 'version_api_tid' column to {project_release_nodes}.
 506   */
 507  function project_release_update_6005() {
 508    $ret = array();
 509  
 510    $spec = array(
 511      'description' => 'The denormalized {term_node}.tid of the API compatibility term for this release, or 0 if the release has no such term.',
 512      'type' => 'int',
 513      'unsigned' => TRUE,
 514      'not null' => FALSE,
 515      'default' => NULL,
 516    );
 517    db_add_field($ret, 'project_release_nodes', 'version_api_tid', $spec);
 518  
 519    // Populate the new column from {term_node}.
 520    $api_vid = _project_release_get_api_vid();
 521    $ret[] = update_sql("UPDATE {project_release_nodes} SET version_api_tid = (SELECT tn.tid FROM {node} n INNER JOIN {term_node} tn ON n.vid = tn.vid INNER JOIN {term_data} td ON tn.tid = td.tid WHERE n.nid = {project_release_nodes}.nid AND td.vid = $api_vid)");
 522  
 523    return $ret;
 524  }
 525  
 526  /**
 527   * Add security_update and update_status columns to {project_release_nodes}.
 528   */
 529  function project_release_update_6006() {
 530    $ret = array();
 531  
 532    $spec = array(
 533      'description' => 'Denormalized flag to record if this release has the "project_release_security_update_tid" taxonomy term set or not',
 534      'type' => 'int',
 535      'size' => 'tiny',
 536      'unsigned' => TRUE,
 537      'not null' => TRUE,
 538      'default' => 0,
 539    );
 540    db_add_field($ret, 'project_release_nodes', 'security_update', $spec);
 541  
 542    if (module_exists('taxonomy')) {
 543      // Populate the new column from {term_node}.
 544      _project_release_check_security_updates($ret);
 545    }
 546  
 547    $spec = array(
 548      'description' => 'Denormalized flag to record the update status for this release. Allowed values: PROJECT_RELEASE_UPDATE_STATUS_CURRENT (0), PROJECT_RELEASE_UPDATE_STATUS_NOT_CURRENT (1), PROJECT_RELEASE_UPDATE_STATUS_NOT_SECURE (2)',
 549      'type' => 'int',
 550      'size' => 'tiny',
 551      'not null' => TRUE,
 552      'default' => 0,
 553    );
 554    db_add_field($ret, 'project_release_nodes', 'update_status', $spec);
 555    // This will be initialized by project_release_check_supported_versions()
 556    // in project_release_update_6008(), so we don't need to do that here.
 557  
 558    return $ret;
 559  }
 560  
 561  /**
 562   * Add the 'version_extra_weight' column to {project_release_nodes}.
 563   */
 564  function project_release_update_6007() {
 565    $ret = array();
 566  
 567    $spec = array(
 568      'type' => 'int',
 569      'not null' => TRUE,
 570      'default' => 0,
 571    );
 572    db_add_field($ret, 'project_release_nodes', 'version_extra_weight', $spec);
 573  
 574    // Initialize the values in the DB based on the existing weights.
 575    _project_release_update_version_extra_weights($ret);
 576  
 577    return $ret;
 578  }
 579  
 580  /**
 581   * Add the {project_release_supported_versions}.latest_security_release field.
 582   */
 583  function project_release_update_6008() {
 584    $ret = array('#finished' => 0);
 585    if (!isset($_SESSION['project_release_update_6008'])) {
 586      $spec = array(
 587        'type' => 'int',
 588        'unsigned' => TRUE,
 589        'default' => NULL,
 590        'not null' => FALSE,
 591      );
 592      db_add_field($ret, 'project_release_supported_versions', 'latest_security_release', $spec);
 593      $_SESSION['project_release_update_6008'] = 0;
 594      $_SESSION['project_release_update_6008_max'] = db_result(db_query("SELECT COUNT(*) FROM {project_release_supported_versions}"));
 595    }
 596  
 597    // Number of rows to convert per batch.
 598    $limit = 20;
 599    while ($limit-- && $item = db_fetch_array(db_query_range("SELECT * FROM {project_release_supported_versions} WHERE latest_security_release IS NULL", 0, 1))) {
 600      // We have a branch we haven't processed yet (latest_security_release is
 601      // still NULL), so we invoke project_release_check_supported_versions() to
 602      // run some queries to determine the recommended, latest, and latest
 603      // security releases on that branch. Normally, it updates
 604      // {project_release_supported_versions} with this data in which case it
 605      // returns TRUE. However, if it returns FALSE, it means we didn't find any
 606      // releases on that branch, and it didn't touch the table. In that case,
 607      // we need to update the table ourselves for this branch to mark
 608      // latest_security_release as 0 (not NULL) so that we don't check this
 609      // branch again.
 610      if (!project_release_check_supported_versions($item['nid'], $item['tid'], $item['major'], FALSE)) {
 611        db_query("UPDATE {project_release_supported_versions} SET latest_security_release = %d WHERE nid = %d AND tid = %d AND major = %d", 0, $item['nid'], $item['tid'], $item['major']);
 612        // If project_release_check_supported_versions() returned FALSE, there
 613        // are no releases on this branch, so there's nothing to initialize
 614        // {project_release_nodes}.update_status for.
 615      }
 616      $_SESSION['project_release_update_6008']++;
 617    }
 618  
 619    if ($_SESSION['project_release_update_6008'] >= $_SESSION['project_release_update_6008_max']) {
 620      // We're done.  Set our new columns to default to 0 from here on out.
 621      $ret[] = update_sql("ALTER TABLE {project_release_supported_versions} ALTER COLUMN latest_security_release SET DEFAULT 0");
 622      unset($_SESSION['project_release_update_6008']);
 623      unset($_SESSION['project_release_update_6008_max']);
 624      $ret['#finished'] = 1;
 625    }
 626    else {
 627      $ret['#finished'] = $_SESSION['project_release_update_6008'] / $_SESSION['project_release_update_6008_max'];
 628    }
 629    return $ret;
 630  }
 631  
 632  /**
 633   * Add the {project_release_nodes}.version_extra_delta field.
 634   *
 635   * Also recompute the latest and recommended releases on each branch, and
 636   * therefore the update_status field, since version_extra_delta is needed
 637   * to properly order alpha10 vs. alpha9, etc.
 638   */
 639  function project_release_update_6009() {
 640    $ret = array('#finished' => 0);
 641    if (!isset($_SESSION['project_release_update_6009'])) {
 642      $spec = array(
 643        'type' => 'int',
 644        'not null' => TRUE,
 645        'default' => 0,
 646        'description' => 'The first span of digits found in version_extra. This is needed because we cannot natural sort natively without a stored procedure.',
 647      );
 648  
 649      db_add_field($ret, 'project_release_nodes', 'version_extra_delta', $spec);
 650  
 651      // Initialize version_extra_delta to -1 to identify the rows to process.
 652      db_query('UPDATE {project_release_nodes} SET version_extra_delta = -1 WHERE version_extra IS NOT NULL');
 653  
 654      $_SESSION['project_release_update_6009'] = 0;
 655      $_SESSION['project_release_update_6009_max'] = db_result(db_query("SELECT COUNT(*) FROM {project_release_nodes} WHERE version_extra IS NOT NULL"));
 656    }
 657  
 658    // Number of rows to convert per batch.
 659    $limit = 20;
 660    while ($limit-- && $item = db_fetch_array(db_query_range("SELECT nid, pid, version_major, version_api_tid, version_extra FROM {project_release_nodes} WHERE version_extra_delta = -1", 0, 1))) {
 661      // Due to the new sorting method, the "recommended" and "latest" releases
 662      // will change on any releases affected by http://drupal.org/node/649254.
 663  
 664      // Determine the correct version_extra_delta and update it.
 665      $match = array();
 666      $nmatch = preg_match('/(\d+)/', $item['version_extra'], $match);
 667      db_query('UPDATE {project_release_nodes} SET version_extra_delta = %d WHERE nid = %d', ($nmatch) ? $match[1] : 0, $item['nid']);
 668  
 669      // Finally, recheck the branch.
 670      // Note: this is ineffecient: we only really need to call this
 671      // once per unique branch we're touching, not for every single
 672      // release, but optimizing this isn't worth the effort, and would
 673      // potentially require an enormous array in $_SESSION that could
 674      // cause its own problems.
 675      project_release_check_supported_versions($item['pid'], $item['version_api_tid'], $item['version_major'], FALSE);
 676  
 677      $_SESSION['project_release_update_6009']++;
 678    }
 679  
 680    if ($_SESSION['project_release_update_6009'] >= $_SESSION['project_release_update_6009_max']) {
 681      // Done. Clean up.
 682      unset($_SESSION['project_release_update_6009']);
 683      unset($_SESSION['project_release_update_6009_max']);
 684      $ret['#finished'] = 1;
 685    }
 686    else {
 687      $ret['#finished'] = $_SESSION['project_release_update_6009'] / $_SESSION['project_release_update_6009_max'];
 688    }
 689    return $ret;
 690  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7