chg: [internal] Use FileAccessTool

pull/8176/head
Jakub Onderka 2022-02-26 17:45:02 +01:00
parent ae07ea534e
commit 74dc9b3681
2 changed files with 7 additions and 11 deletions

View File

@ -417,15 +417,14 @@ class WarninglistsController extends AppController
public function delete($id)
{
if ($this->request->is('post')) {
$id = intval($id);
$id = (int)$id;
$result = $this->Warninglist->quickDelete($id);
if ($result) {
$this->Flash->success(__('Warninglist successfully deleted.'));
$this->redirect(array('controller' => 'warninglists', 'action' => 'index'));
} else {
$this->Flash->error(__('Warninglists could not be deleted.'));
$this->redirect(array('controller' => 'warninglists', 'action' => 'index'));
$this->Flash->error(__('Warninglist could not be deleted.'));
}
$this->redirect(['controller' => 'warninglists', 'action' => 'index']);
} else {
if ($this->request->is('ajax')) {
$this->set('id', $id);

View File

@ -1,6 +1,7 @@
<?php
App::uses('AppModel', 'Model');
App::uses('CidrTool', 'Tools');
App::uses('FileAccessTool', 'Tools');
/**
* @property WarninglistType $WarninglistType
@ -277,10 +278,7 @@ class Warninglist extends AppModel
$directories = glob(APP . 'files' . DS . 'warninglists' . DS . 'lists' . DS . '*', GLOB_ONLYDIR);
$updated = array('success' => [], 'fails' => []);
foreach ($directories as $dir) {
$file = new File($dir . DS . 'list.json');
$list = $this->jsonDecode($file->read());
$file->close();
$list = FileAccessTool::readJsonFromFile($dir . DS . 'list.json');
if (!isset($list['version'])) {
$list['version'] = 1;
}
@ -803,7 +801,7 @@ class Warninglist extends AppModel
if (isset($data['WarninglistEntry'])) {
$this->WarninglistEntry->deleteAll(['warninglist_id' => $id]);
$entriesToInsert = [];
foreach ($data['WarninglistEntry'] as &$entry) {
foreach ($data['WarninglistEntry'] as $entry) {
$entriesToInsert[] = [$entry['value'], isset($entry['comment']) ? $entry['comment'] : null, $id];
}
$db->insertMulti(
@ -845,8 +843,7 @@ class Warninglist extends AppModel
$this->regenerateWarninglistCaches($this->data['Warninglist']['id']);
}
$pubToZmq = Configure::read('Plugin.ZeroMQ_enable') && Configure::read('Plugin.ZeroMQ_warninglist_notifications_enable');
if ($pubToZmq) {
if ($this->pubToZmq('warninglist')) {
$warninglist = $this->find('first', [
'conditions' => ['id' => $this->data['Warninglist']['id']],
'contains' => ['WarninglistEntry', 'WarninglistType'],