1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Files admin controller |
5
|
|
|
* |
6
|
|
|
* @author Alexey Krupskiy <[email protected]> |
7
|
|
|
* @link http://inji.ru/ |
8
|
|
|
* @copyright 2015 Alexey Krupskiy |
9
|
|
|
* @license https://github.com/injitools/cms-Inji/blob/master/LICENSE |
10
|
|
|
*/ |
11
|
|
|
class FilesController extends adminController { |
|
|
|
|
12
|
|
|
|
13
|
|
|
public function managerForEditorAction() { |
14
|
|
|
$this->view->page(['page' => 'blank']); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function clearMissingAction() { |
18
|
|
|
if (!empty($_POST['files'])) { |
19
|
|
|
$files = \Files\File::getList(['where' => ['id', $_POST['files'], 'IN']]); |
|
|
|
|
20
|
|
|
foreach ($files as $file) { |
21
|
|
|
$file->delete(); |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
if (!empty($_POST['untrackedfiles'])) { |
25
|
|
|
foreach ($_POST['untrackedfiles'] as $file) { |
26
|
|
|
if (strpos($file, '..') !== false || strpos($file, '/static/mediafiles') !== 0) { |
27
|
|
|
continue; |
28
|
|
|
} |
29
|
|
|
unlink(\App::$primary->path . $file); |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
$usedImages = []; |
33
|
|
|
$installedModules = \Module::getInstalled(App::$primary); |
34
|
|
|
foreach ($installedModules as $module) { |
35
|
|
|
foreach (\Module::getModels($module) as $modelPath => $modelName) { |
36
|
|
|
foreach ($modelName::$cols as $colName => $col) { |
37
|
|
|
if ($col['type'] == 'image') { |
38
|
|
|
$items = $modelName::getList(['where' => [$colName, 0, '!='], 'array' => true, 'key' => false, 'cols' => $modelName::colPrefix() . $colName]); |
39
|
|
|
if ($items) { |
40
|
|
|
foreach ($items as $item) { |
41
|
|
|
$usedImages[$item[$modelName::colPrefix() . $colName]] = true; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
$allImages = \Files\File::getList(['key' => 'path', 'array' => true, 'cols' => 'file_path']); |
50
|
|
|
$result = []; |
51
|
|
|
Tools::getDirContents(\App::$primary->path . '/static/mediafiles', $result, '/static/mediafiles'); |
|
|
|
|
52
|
|
|
echo '<form method="post"><table>'; |
53
|
|
|
foreach ($result as $file) { |
54
|
|
|
if (!isset($allImages[$file])) { |
55
|
|
|
echo '<tr>'; |
56
|
|
|
echo "<td><input type='checkbox' name='untrackedfiles[]' value='{$file}' checked /></td>"; |
57
|
|
|
echo "<td></td>"; |
58
|
|
|
echo "<td></td>"; |
59
|
|
|
echo "<td>untracked file</td>"; |
60
|
|
|
echo "<td></td>"; |
61
|
|
|
echo "<td><a href='{$file}' target='_blank'>{$file}</a></td>"; |
62
|
|
|
echo '</tr>'; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$missingImages = \Files\File::getList(['where' => ['id', array_keys($usedImages), 'NOT IN'], 'key' => 'path', 'array' => true]); |
68
|
|
|
$texts = ''; |
69
|
|
|
foreach (\Materials\Material::getList(['array' => true]) as $material) { |
70
|
|
|
$texts .= $material['material_preview']; |
71
|
|
|
$texts .= $material['material_text']; |
72
|
|
|
} |
73
|
|
|
if (!empty($installedModules['TextBlocks'])) { |
74
|
|
|
foreach (\TextBlocks\Block::getList(['array' => true]) as $block) { |
75
|
|
|
$texts .= $block['block_text']; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
$deleted = 0; |
79
|
|
|
foreach ($missingImages as $path => $file) { |
80
|
|
|
if (strpos($texts, $path)) { |
81
|
|
|
unset($missingImages[$path]); |
82
|
|
|
$deleted++; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
foreach ($missingImages as $path => $file) { |
86
|
|
|
echo '<tr>'; |
87
|
|
|
echo "<td><input type='checkbox' name='files[]' value='{$file['file_id']}' " . ($file['file_upload_code'] == 'MigrationUpload' ? 'checked' : '') . " /></td>"; |
88
|
|
|
echo "<td>{$file['file_id']}</td>"; |
89
|
|
|
echo "<td>{$file['file_code']}</td>"; |
90
|
|
|
echo "<td>{$file['file_upload_code']}</td>"; |
91
|
|
|
echo "<td>{$file['file_name']}</td>"; |
92
|
|
|
echo "<td><a href='{$path}' target='_blank'>{$path}</a></td>"; |
93
|
|
|
echo '</tr>'; |
94
|
|
|
} |
95
|
|
|
echo '</table><button>Удалить</button></form>'; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths