|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* ****************************************************************************** |
|
5
|
|
|
* Copyright 2011-2017 DANTE Ltd. and GÉANT on behalf of the GN3, GN3+, GN4-1 |
|
6
|
|
|
* and GN4-2 consortia |
|
7
|
|
|
* |
|
8
|
|
|
* License: see the web/copyright.php file in the file structure |
|
9
|
|
|
* ****************************************************************************** |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace web\lib\admin; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* This class factors out some functions which are done both interactively in |
|
16
|
|
|
* the superadmin area and by scripts in utils/ to avoid code duplication across |
|
17
|
|
|
* the two. |
|
18
|
|
|
*/ |
|
19
|
|
|
class Maintenance { |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* delete our various cache and temp dirs if they are not needed any more |
|
23
|
|
|
* @return int the number of deleted temporary directories |
|
24
|
|
|
*/ |
|
25
|
|
|
public static function deleteObsoleteTempDirs() { |
|
26
|
|
|
$downloadsDirs = [ |
|
27
|
|
|
'site_installers' => dirname(dirname(dirname(dirname(__FILE__)))) . "/var/installer_cache", |
|
28
|
|
|
'silverbullet' => dirname(dirname(dirname(dirname(__FILE__)))) . "/var/silverbullet" |
|
29
|
|
|
]; |
|
30
|
|
|
$tm = time(); |
|
31
|
|
|
$i = 0; |
|
32
|
|
|
$Cache = []; |
|
33
|
|
|
$dbHandle = \core\DBConnection::handle("FRONTEND"); |
|
34
|
|
|
$result = $dbHandle->exec("SELECT download_path FROM downloads WHERE download_path IS NOT NULL"); |
|
35
|
|
|
// SELECT -> mysqli_result, not a boolean |
|
36
|
|
|
while ($r = mysqli_fetch_row(/** @scrutinizer ignore-type */ $result)) { |
|
37
|
|
|
$e = explode('/', $r[0]); |
|
38
|
|
|
$Cache[$e[count($e) - 2]] = 1; |
|
39
|
|
|
} |
|
40
|
|
|
foreach ($downloadsDirs as $downloads) { |
|
41
|
|
|
if ($handle = opendir($downloads)) { |
|
42
|
|
|
/* This is the correct way to loop over the directory. */ |
|
43
|
|
|
while (false !== ($entry = readdir($handle))) { |
|
44
|
|
|
if ($entry === '.' || $entry === '..' || $entry === '.gitignore') { |
|
45
|
|
|
continue; |
|
46
|
|
|
} |
|
47
|
|
|
$ftime = $tm - filemtime($downloads . '/' . $entry); |
|
48
|
|
|
if ($ftime < 3600) { |
|
49
|
|
|
continue; |
|
50
|
|
|
} |
|
51
|
|
|
if (isset($Cache[$entry])) { |
|
52
|
|
|
continue; |
|
53
|
|
|
} |
|
54
|
|
|
\core\common\Entity::rrmdir($downloads . '/' . $entry); |
|
55
|
|
|
$i = $i + 1; |
|
56
|
|
|
print "$entry\n"; |
|
57
|
|
|
} |
|
58
|
|
|
closedir($handle); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
return $i; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|