-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbase.php
More file actions
102 lines (85 loc) · 2.29 KB
/
base.php
File metadata and controls
102 lines (85 loc) · 2.29 KB
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
<?php
/**
* @package Porter
* @author Alan Hardman <alan@phpizza.com>
* @version 1.3.1
*/
namespace Plugin\Porter;
class Base extends \Plugin {
/**
* Initialize the plugin
*/
public function _load() {
}
/**
* Check if plugin is installed
* @return bool
*/
public function _installed() {
return true;
}
/**
* Generate page for admin panel
*/
public function _admin() {
$f3 = \Base::instance();
if($f3->get("POST.run")) {
$this->run();
}
$f3->set("UI", $f3->get("UI") . ";./app/plugin/porter/view/");
echo \Helper\View::instance()->render("porter-admin.html");
}
/**
* Run all Porter tasks
*/
public function run() {
$f3 = \Base::instance();
$db = $f3->get("db.instance");
if($debug = $f3->get("DEBUG")) {
$log = new \Log("porter.log");
}
// Purge deleted files
$file = new \Model\Issue\File;
$files = $file->find("deleted_date IS NOT NULL AND deleted_date < DATE_SUB(NOW(), INTERVAL 5 DAY)");
foreach($files as $f) {
if(!$f->disk_filename) {
continue;
}
$result = @unlink($f->disk_filename);
if($debug) {
if($result) {
$log->write("Deleted " . $f->disk_filename);
} else {
$log->write("Failed to delete " . $f->disk_filename);
}
}
$f->disk_filename = '';
$f->save();
}
// Clean up database
$rows = $db->exec("UPDATE issue SET parent_id = NULL WHERE parent_id = '0'");
if($debug) {
$log->write("Fixed parent_id on {$rows} issues");
}
$rows = $db->exec("UPDATE issue SET closed_date = NULL WHERE closed_date = '0000-00-00 00:00:00'");
if($debug) {
$log->write("Fixed closed_date on {$rows} issues");
}
$rows = $db->exec("UPDATE issue SET deleted_date = NULL WHERE deleted_date = '0000-00-00 00:00:00'");
if($debug) {
$log->write("Fixed deleted_date on {$rows} issues");
}
$rows = $db->exec("UPDATE issue SET repeat_cycle = NULL WHERE repeat_cycle = 'none'");
if($debug) {
$log->write("Cleaned repeat_cycle on {$rows} issues");
}
$rows = $db->exec("UPDATE user SET api_key = NULL WHERE api_key = ''");
if($debug) {
$log->write("Cleaned api_key on {$rows} users");
}
$rows = $db->exec("DELETE FROM session WHERE created < ?", date("Y-m-d H:i:s", time() - $f3->get("session_lifetime")));
if($debug) {
$log->write("Deleted {$rows} old sessions");
}
}
}