This repository has been archived by the owner on Dec 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.php
96 lines (79 loc) · 2.55 KB
/
setup.php
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
<?php
/**
* @package ThumbnailsAddon
*/
require_once ADDON_DIR . 'thumbnails/info.php';
class addon_thumbnails_setup extends addon_thumbnails_info
{
public function install ()
{
$db = $cron = $admin = true;
include(GEO_BASE_DIR . 'get_common_vars.php');
$sql[] = "CREATE TABLE IF NOT EXISTS " . self::THUMBNAILS_TABLE . " (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`image_id` int(10) unsigned NOT NULL,
`size_id` int(3) unsigned NOT NULL,
`filename` varchar(20) NOT NULL,
`width` int(5) unsigned NOT NULL,
`height` int(5) unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unique` (`image_id`,`size_id`)
) DEFAULT CHARSET=utf8;";
$sql[] = "CREATE TABLE IF NOT EXISTS " . self::JOBS_TABLE . " (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`job` enum('add_thumbnails','remove_thumbnails','add_size','remove_size') NOT NULL,
`target` int(4) unsigned NOT NULL,
`status` enum('pending','running','failed', 'success') NOT NULL DEFAULT 'pending',
`error` varchar(255) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;";
$errors = $this->executeSQL($sql, $db);
if (!empty($errors)) {
foreach ($errors as $error) {
$admin->userError('Database execution error, install failed: ' . $error);
}
return false;
}
array(
'name' => self::RUN_JOBS_CRON,
'type' => 'addon',
'interval' => 10
);
$add_cron_result = $cron->set(self::RUN_JOBS_CRON, 'addon', 10);
if (!$add_cron_result) {
$admin->userError('Cron task run_jobs failed to be added.');
return false;
}
return true;
}
public function uninstall ()
{
$db = $cron = $admin = true;
include(GEO_BASE_DIR . 'get_common_vars.php');
$sql[] = 'DROP TABLE IF EXISTS ' . self::THUMBNAILS_TABLE;
$sql[] = 'DROP TABLE IF EXISTS ' . self::JOBS_TABLE;
$errors = $this->executeSQL($sql, $db);
if (!empty($errors)) {
foreach ($errors as $error) {
$admin->userError('Database execution error, un-install failed: ' . $error);
}
return false;
}
$remove_cron_result = $cron->rem(self::RUN_JOBS_CRON);
if (!$remove_cron_result) {
$admin->userError('Error removing run_jobs cron task, un-install failed.');
return false;
}
return true;
}
private function executeSQL ($sql, $db)
{
foreach($sql as $query) {
$result = $db->Execute($query);
if (!$result) {
$errors[] = $db->ErrorMsg();
}
}
return $errors;
}
}