forked from sinistar/content_moderation
-
Notifications
You must be signed in to change notification settings - Fork 1
/
content_moderation.install
116 lines (102 loc) · 4.51 KB
/
content_moderation.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
// $Id:$
/**
* @file
* Install file for the content moderation module.
*
* Copyright (c) 2010 Impressive.media
* Author: Eugen Mayer
*
*/
/**
* Implementation of hook_install().
*/
function content_moderation_install() {
// Create tables.
drupal_install_schema('content_moderation');
_content_moderation_insert_values();
db_query("UPDATE {system} SET weight = 5 WHERE name = 'content_moderation'");
}
/**
* Implementation of hook_schema().
*/
function content_moderation_schema() {
$schema['content_moderation_revision_state'] = array(
'description' => t('Saves the current live vid of a node'),
'fields' => array(
'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'state' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE),
),
'primary key' => array('vid'),
);
$schema['content_moderation_states'] = array(
'description' => t('Defines all possible states'),
'fields' => array(
'name' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE),
'descr' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE),
'weight' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'small'),
),
'unique keys' => array('name' => array('name'))
);
$schema['content_moderation_node_history'] = array(
'fields' => array(
'hid' => array('type' => 'serial', 'not null' => TRUE),
'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'),
'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'),
'old_state_name' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE),
'state_name' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE),
'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'),
'stamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'),
'comment' => array('type' => 'text', 'size' => 'big', 'not null' => FALSE)),
'primary key' => array('hid'),
);
$schema['content_moderation_transition'] = array(
'description' => t('Defines the valid transitions for states'),
'fields' => array(
'from_name' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE),
'to_name' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE),
'ntype' => array('type' => 'varchar', 'length' => '40', 'not null' => FALSE),
),
);
return $schema;
}
function _content_moderation_insert_values() {
$states[] = array('name' => 'none');
$states[] = array('name' => 'review');
$states[] = array('name' => 'approve');
$states[] = array('name' => 'live');
foreach($states as $state) {
// See http://drupal.org/node/568640 to change this after it's fixed.
db_query('INSERT INTO {content_moderation_states} (`name`) VALUES("%s")', $state);
//drupal_write_record('content_moderation_states', $state);
}
// Transitions.
$transitions[] = array('none', 'review', 'all');
$transitions[] = array('review', 'approve', 'all');
$transitions[] = array('approve', 'live', 'all');
$transitions[] = array('review', 'none', 'all');
$transitions[] = array('approve', 'review', 'all');
$transitions[] = array('approve', 'none', 'all');
foreach($transitions AS $transition) {
// See http://drupal.org/node/568640 to change this after it's fixed.
db_query('INSERT INTO {content_moderation_transition} (from_name,to_name,ntype) VALUES("' . $transition[0] . '","' . $transition[1] . '","' . $transition[2] . '")');
//drupal_write_record('content_moderation_transition', $transition);
}
}
function content_moderation_update_6001() {
update_sql('UPDATE node INNER JOIN node_revisions nr ON node.vid = nr.vid SET node.changed = nr.timestamp');
return array();
}
function content_moderation_update_6003() {
$ret = array();
db_add_field($ret, 'content_moderation_states', 'weight', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'small'));
return $ret;
}
/**
* Implementation of hook_uninstall().
*/
function content_moderation_uninstall() {
// Remove tables.
drupal_uninstall_schema('content_moderation');
}