You are here

function node_gallery_update_6304 in Node Gallery 6.3

NG2 didn't add a gallery to the table until it contained images. This update hook gets those empty (or otherwise missing) galleries into the table. http://drupal.org/node/1008006

File

./node_gallery.install, line 892
Install, update and uninstall functions for the node_gallery module.

Code

function node_gallery_update_6304() {
  $ret = array();
  $types = array();
  $result = db_query('SELECT gallery_type FROM {node_gallery_relationships}');
  while ($row = db_fetch_array($result)) {
    $types[] = $row['gallery_type'];
  }
  $sql = 'SELECT nid as gid FROM {node} n LEFT JOIN {node_gallery_galleries} ng on ng.gid = n.nid WHERE n.type IN (' . db_placeholders($types, 'varchar') . ') AND ng.gid IS NULL';
  $result = db_query($sql, $types);
  $count = 0;
  while ($gallery = db_fetch_object($result)) {
    if (drupal_write_record('node_gallery_galleries', $gallery)) {
      $count++;
    }
  }
  if ($count > 0) {
    $ret[] = array(
      'success' => TRUE,
      'query' => t('Added !count empty galleries into node_gallery_galleries table.', array(
        '!count' => $count,
      )),
    );
  }
  return $ret;
}