publication_date.install in Publication Date 6
Same filename and directory in other branches
@author Clever Age @author Emmanuelle Gouleau @author Tristan Marly
File
publication_date.installView source
<?php
/**
* @file
*
* @author Clever Age
* @author Emmanuelle Gouleau
* @author Tristan Marly
*
*/
/**
* Implementation of hook_schema().
*/
function publication_date_schema() {
$schema['publication_date'] = array(
'description' => 'Keep the publication timestamp for each node.',
'fields' => array(
'nid' => array(
'description' => 'The {node}.nid of the node.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'published_at' => array(
'description' => 'The timestamp of the node publication.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'published_at' => array(
'published_at',
),
),
'primary key' => array(
'nid',
),
);
return $schema;
}
/**
* Implementation of hook_install().
*/
function publication_date_install() {
// create tables
drupal_install_schema('publication_date');
// update existing nodes
_publication_date_update_existing();
// The hooks of this module must be called after some other modules (scheduler, ...)
update_sql("UPDATE {system} SET weight = 99 WHERE name = 'publication_date'");
}
/**
* Implementation of hook_uninstall().
*/
function publication_date_uninstall() {
// drop tables
drupal_uninstall_schema('publication_date');
}
/**
* Function to update the existing nodes on install so sorting will work properly.
*/
function _publication_date_update_existing() {
$sql = "INSERT INTO {publication_date} SELECT nid,created FROM {node} where status = 1";
db_query($sql);
}
Functions
Name | Description |
---|---|
publication_date_install | Implementation of hook_install(). |
publication_date_schema | Implementation of hook_schema(). |
publication_date_uninstall | Implementation of hook_uninstall(). |
_publication_date_update_existing | Function to update the existing nodes on install so sorting will work properly. |