feat(admin): remove old assets
This commit is contained in:
@@ -94,6 +94,7 @@ class ControllerExtensionModuleTgshop extends Controller
|
|||||||
|
|
||||||
if ($hasConfig) {
|
if ($hasConfig) {
|
||||||
$this->updateConfigFromDefaults();
|
$this->updateConfigFromDefaults();
|
||||||
|
$this->cleanUpOldAssets();
|
||||||
$this->config();
|
$this->config();
|
||||||
} else {
|
} else {
|
||||||
$this->init();
|
$this->init();
|
||||||
@@ -132,7 +133,6 @@ class ControllerExtensionModuleTgshop extends Controller
|
|||||||
foreach ($data['settings'] as $configs) {
|
foreach ($data['settings'] as $configs) {
|
||||||
foreach ($configs as $key => $config) {
|
foreach ($configs as $key => $config) {
|
||||||
if ($config['type'] === 'image') {
|
if ($config['type'] === 'image') {
|
||||||
|
|
||||||
if (isset($this->request->post[$key]) && is_file(DIR_IMAGE . $this->request->post[$key])) {
|
if (isset($this->request->post[$key]) && is_file(DIR_IMAGE . $this->request->post[$key])) {
|
||||||
$data[$key] = $this->model_tool_image->resize($this->request->post[$key], 100, 100);
|
$data[$key] = $this->model_tool_image->resize($this->request->post[$key], 100, 100);
|
||||||
} elseif ($this->config->get($key) && is_file(DIR_IMAGE . $this->config->get($key))) {
|
} elseif ($this->config->get($key) && is_file(DIR_IMAGE . $this->config->get($key))) {
|
||||||
@@ -225,10 +225,10 @@ class ControllerExtensionModuleTgshop extends Controller
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
$app->bind(OcRegistryDecorator::class, fn () => new OcRegistryDecorator($this->registry));
|
$app->bind(OcRegistryDecorator::class, fn() => new OcRegistryDecorator($this->registry));
|
||||||
|
|
||||||
$app
|
$app
|
||||||
->withLogger(fn () => new OpenCartLogAdapter($this->log, 'TeleCartAdmin'))
|
->withLogger(fn() => new OpenCartLogAdapter($this->log, 'TeleCartAdmin'))
|
||||||
->bootAndHandleRequest();
|
->bootAndHandleRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -509,7 +509,7 @@ HTML,
|
|||||||
$map = [];
|
$map = [];
|
||||||
|
|
||||||
foreach ($this->model_customer_customer_group->getCustomerGroups() as $customer_group) {
|
foreach ($this->model_customer_customer_group->getCustomerGroups() as $customer_group) {
|
||||||
$map[(int)$customer_group['customer_group_id']] = $customer_group['name'];
|
$map[(int) $customer_group['customer_group_id']] = $customer_group['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $map;
|
return $map;
|
||||||
@@ -521,7 +521,7 @@ HTML,
|
|||||||
$map = [];
|
$map = [];
|
||||||
|
|
||||||
foreach ($statuses as $item) {
|
foreach ($statuses as $item) {
|
||||||
$map[(int)$item['order_status_id']] = $item['name'];
|
$map[(int) $item['order_status_id']] = $item['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $map;
|
return $map;
|
||||||
@@ -550,4 +550,64 @@ HTML,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function cleanUpOldAssets(): void
|
||||||
|
{
|
||||||
|
$spaPath = rtrim(DIR_IMAGE, '/') . '/catalog/tgshopspa';
|
||||||
|
$assetsPath = $spaPath . '/assets';
|
||||||
|
$manifestPath = $spaPath . '/manifest.json';
|
||||||
|
if (! file_exists($manifestPath)) {
|
||||||
|
$this->log->write('[TELECART] Файл manifest.json не найден — очистка пропущена.');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$contents = json_decode(file_get_contents($manifestPath), true, 512, JSON_THROW_ON_ERROR);
|
||||||
|
|
||||||
|
$entry = $contents['index.html'] ?? null;
|
||||||
|
if (! $entry) {
|
||||||
|
throw new RuntimeException('[TELECART] Некорректный manifest.json — отсутствует ключ index.html.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$keep = [$entry['file']];
|
||||||
|
if (! empty($entry['css'])) {
|
||||||
|
foreach ($entry['css'] as $css) {
|
||||||
|
$keep[] = $css;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$deletedFiles = 0;
|
||||||
|
$keptFiles = 0;
|
||||||
|
|
||||||
|
foreach (glob($assetsPath . '/*') as $file) {
|
||||||
|
$ext = pathinfo($file, PATHINFO_EXTENSION);
|
||||||
|
if (! in_array($ext, ['js', 'css'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$relative = 'assets/' . basename($file);
|
||||||
|
if (in_array($relative, $keep, true)) {
|
||||||
|
$keptFiles++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_file($file)) {
|
||||||
|
unlink($file);
|
||||||
|
$deletedFiles++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->log->write(
|
||||||
|
sprintf(
|
||||||
|
'[TELECART] Очистка assets завершена. Удалено: %d, оставлено: %d',
|
||||||
|
$deletedFiles,
|
||||||
|
$keptFiles
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} catch (JsonException $e) {
|
||||||
|
$this->log->write('[TELECART] Ошибка декодирования файла manifest.json: ' . $e->getMessage());
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->log->write('[TELECART] Ошибка удаления старых assets: ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user