photos_access.install in Album Photos 7.3
Same filename and directory in other branches
Install, update, and uninstall functions for the Photos Access module.
File
photos_access/photos_access.installView source
<?php
/**
* @file
* Install, update, and uninstall functions for the Photos Access module.
*/
/**
* Implements hook_schema().
*/
function photos_access_schema() {
$schema['photos_access_album'] = array(
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
),
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'viewid' => array(
'type' => 'int',
'size' => 'tiny',
'length' => 1,
'default' => 0,
'description' => '0: Open, 1: Locked, 2: Password, 3: User list',
),
'pass' => array(
'type' => 'varchar',
'length' => 128,
'default' => '',
),
),
'indexes' => array(
'nid' => array(
'nid',
),
),
'primary key' => array(
'id',
),
);
$schema['photos_access_user'] = array(
'fields' => array(
'id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'collaborate' => array(
'type' => 'int',
'size' => 'tiny',
'length' => 1,
'default' => 0,
),
),
'indexes' => array(
'uid' => array(
'uid',
),
),
);
return $schema;
}
/**
* Implements hook_disable().
*/
function photos_access_disable() {
if (module_exists('photos')) {
variable_set('photos_access_photos', 0);
}
}
/**
* Implements hook_uninstall().
*/
function photos_access_uninstall() {
$types = node_type_get_types();
foreach ($types as $type) {
variable_del('photos_access_' . $type->type);
}
}
/**
* Upgrade Photos Access from D6 to D7.
*/
function photos_access_update_7000() {
if (db_table_exists('x_album_ac')) {
// Drop all new empty tables.
db_drop_table('photos_access_album');
db_drop_table('photos_access_user');
// Rename existing tables.
db_rename_table('x_album_ac', 'photos_access_album');
db_rename_table('x_album_acuser', 'photos_access_user');
}
}
/**
* Add collaborate column to {photos_access_user}.
*/
function photos_access_update_7301() {
// Add collaborate column to {'photos_access_user'}.
$spec = array(
'type' => 'int',
'size' => 'tiny',
'length' => 1,
'default' => 0,
);
db_add_field('photos_access_user', 'collaborate', $spec);
// Update {'photos_access_user'}.collaborate to match {'photos_access_album'}.updateid.
// Attempt to clean up {photos_access_album} duplicate entries.
// Update {photos_access_user}.id to match the correct {photos_access_album}.id for nid.
$new_id = array();
$results = db_query("SELECT * FROM {photos_access_album}");
foreach ($results as $result) {
if (isset($new_id[$result->nid])) {
$id = $new_id[$result->nid];
// Update {photos_access_user}.id
db_update('photos_access_user')
->fields(array(
'id' => $id,
'collaborate' => $result->updateid,
))
->condition('id', $result->id)
->execute();
// Make sure new records are not set to open by default.
if ($result->viewid > 0) {
db_update('photos_access_album')
->fields(array(
'viewid' => $result->viewid,
))
->condition('id', $id)
->execute();
}
// Preserve album passwords.
if ($result->pass != 1) {
db_update('photos_access_album')
->fields(array(
'pass' => $result->pass,
))
->condition('id', $id)
->execute();
}
// Delete duplicate entries in {photos_access_album}.
db_delete('photos_access_album')
->condition('id', $result->id)
->execute();
}
else {
$new_id[$result->nid] = $result->id;
db_update('photos_access_user')
->fields(array(
'collaborate' => $result->updateid,
))
->condition('id', $result->id)
->execute();
}
}
// Remove updateid from {'photos_access_album'}.
db_drop_field('photos_access_album', 'updateid');
// Rebuild permissions.
node_access_rebuild(TRUE);
}
Functions
Name![]() |
Description |
---|---|
photos_access_disable | Implements hook_disable(). |
photos_access_schema | Implements hook_schema(). |
photos_access_uninstall | Implements hook_uninstall(). |
photos_access_update_7000 | Upgrade Photos Access from D6 to D7. |
photos_access_update_7301 | Add collaborate column to {photos_access_user}. |