-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconvertfile.install
76 lines (68 loc) · 2.21 KB
/
convertfile.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
<?php
/**
* @file
* Functionality related to module install and uninstall.
*
* Install database schema, default variables and post a friendly drupal
* message each time the module is enabled. Remove database schema and
* variables when module is uninstalled.
*/
require_once('convertfile.db.conversion.inc');
/**
* Implements hook_enable().
*/
function convertfile_enable() {
// Enable help hook text.
variable_set('convertfile_help', TRUE);
// Generate a friendly message to inform the admin what to do next after
// enabling the module.
drupal_set_message(t('Please configure the module at') . ' <a href="/admin/config/convertfile/settings">/admin/config/convertfile/settings</a>', 'status');
}
/**
* Implements hook_uninstall().
*/
function convertfile_uninstall() {
// Get module variables
$results = db_query("SELECT v.name FROM {variable} AS v WHERE v.name LIKE '%s%%'", 'convertfile_');
// Remove variables
while ($row = $results->fetchAssoc()) {
variable_del($row['name']);
}
}
/**
* Implements hook_schema().
*/
function convertfile_schema() {
$schema = convertfile_db_conversion_schema();
return $schema;
}
/**
* Implements hook_update_N().
*
* Rename table name and add mimetype to backup file data.
*/
function convertfile_update_7100(&$sandbox) {
// Rename the table.
$sql = "ALTER TABLE convertfile_conversion RENAME convertfile_backup";
db_query($sql);
cache_clear_all();
// Add new field to table.
$schema = drupal_get_schema(CONVERTFILE_DB_CONVERSION);
db_add_field(CONVERTFILE_DB_CONVERSION, 'mimetype', $schema['fields']['mimetype']);
// Update any existing rows mimetype.
$results = db_select(CONVERTFILE_DB_CONVERSION, 'c')
->fields('c')
->condition('mimetype', '', '=')
->execute()
->fetchAll();
if ($results) {
$count = 0;
foreach($results as $result) {
$file = file_load($result->fid_backup);
$sql = "UPDATE " . CONVERTFILE_DB_CONVERSION . " SET mimetype='{$file->filemime}' WHERE cid={$result->cid}";
db_query($sql);
$count++;
}
}
return t("Database convertfile_conversion has been renamed to convertfile_backup. New field mimetype has been added. {$count} rows have had their mimetype value updated.");
}