You are here

function photos_update_5 in Album Photos 6.2

File

./photos.install, line 270

Code

function photos_update_5() {
  $ret = array();
  $schema['x_count'] = array(
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'cid' => array(
        'type' => 'int',
        'default' => 0,
        'not null' => TRUE,
      ),
      'changed' => array(
        'type' => 'int',
        'default' => 0,
        'not null' => TRUE,
      ),
      'type' => array(
        'type' => 'varchar',
        'length' => 12,
        'default' => '',
        'not null' => TRUE,
      ),
      'value' => array(
        'type' => 'int',
        'default' => 0,
        'not null' => TRUE,
      ),
    ),
    'indexes' => array(
      'cid' => array(
        'cid',
      ),
      'type' => array(
        'type',
      ),
      'value' => array(
        'value',
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  db_create_table($ret, 'x_count', $schema['x_count']);
  $site_album_count = db_result(db_query('SELECT count(pid) FROM {x_album}'));
  $site_image_count = db_result(db_query('SELECT count(fid) FROM {x_image}'));
  db_query("INSERT INTO {x_count} (cid, changed, type, value) VALUES (0, %d, '%s', %d), (0, %d, '%s', %d)", time(), 'site_album', $site_album_count, time(), 'site_image', $site_image_count);
  $result = db_query('SELECT uid FROM {users} WHERE uid != 0 ORDER BY uid ASC');
  while ($image = db_fetch_object($result)) {
    $album_count = db_result(db_query('SELECT count(x.pid) FROM {x_album} x INNER JOIN {node} n ON x.pid = n.nid WHERE n.uid = %d', $image->uid));
    $image_count = db_result(db_query('SELECT count(x.fid) FROM {x_image} x INNER JOIN {files} f ON x.fid = f.fid WHERE f.uid = %d', $image->uid));
    db_query("INSERT INTO {x_count} (cid, changed, type, value) VALUES (%d, %d, '%s', %d), (%d, %d, '%s', %d)", $image->uid, time(), 'user_album', $album_count, $image->uid, time(), 'user_image', $image_count);
  }
  $result = db_query('SELECT pid FROM {x_album}');
  while ($t = db_fetch_object($result)) {
    photos_set_count('node_album', $t->pid);
  }
  $result = db_query('SELECT DISTINCT(nid) FROM {x_node}');
  while ($t = db_fetch_object($result)) {
    photos_set_count('node_node', $t->nid);
  }
  return $ret;
}