chg: [audit log] change field renamed to changed

- change is a reserved keyword
- this way quoting of field names is no longer needed in the cakePHP settings
pull/79/head
iglocska 2021-11-25 00:57:31 +01:00
parent a4f6e06e7a
commit cc5c750de8
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
8 changed files with 46 additions and 18 deletions

View File

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
use Migrations\AbstractMigration;
final class AuditChanged extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change(): void
{
$exists = $this->table('audit_logs')->hasColumn('change');
if ($exists) {
$this->table('audit_logs')
->renameColumn('change', 'changed')
->update();
}
}
}

View File

@ -160,7 +160,7 @@ class AppController extends Controller
'model' => 'Users',
'model_id' => $user['id'],
'model_title' => $user['username'],
'change' => []
'changed' => []
]);
if (!empty($user)) {
$this->Authentication->setIdentity($user);
@ -172,7 +172,7 @@ class AppController extends Controller
'model' => 'Users',
'model_id' => $user['id'],
'model_title' => $user['name'],
'change' => []
'changed' => []
]);
}
}

View File

@ -23,7 +23,7 @@ class AuditLogsController extends AppController
'quickFilters' => $this->quickFilterFields,
'afterFind' => function($data) {
$data['request_ip'] = inet_ntop(stream_get_contents($data['request_ip']));
$data['change'] = stream_get_contents($data['change']);
$data['changed'] = stream_get_contents($data['changed']);
return $data;
}
]);

View File

@ -718,11 +718,11 @@ class RestResponseComponent extends Component
'operators' => array('equal'),
'help' => __('A valid x509 certificate ')
),
'change' => array(
'changed' => array(
'input' => 'text',
'type' => 'string',
'operators' => array('equal'),
'help' => __('The text contained in the change field')
'help' => __('The text contained in the changed field')
),
'change_pw' => array(
'input' => 'radio',

View File

@ -170,7 +170,7 @@ class UsersController extends AppController
'model' => 'Users',
'model_id' => $user['id'],
'model_title' => $user['name'],
'change' => []
'changed' => []
]);
$target = $this->Authentication->getLoginRedirect() ?? '/instance/home';
return $this->redirect($target);
@ -181,7 +181,7 @@ class UsersController extends AppController
'model' => 'Users',
'model_id' => 0,
'model_title' => 'unknown_user',
'change' => []
'changed' => []
]);
$this->Flash->error(__('Invalid username or password'));
}
@ -199,7 +199,7 @@ class UsersController extends AppController
'model' => 'Users',
'model_id' => $user['id'],
'model_title' => $user['name'],
'change' => []
'changed' => []
]);
$this->Authentication->logout();
$this->Flash->success(__('Goodbye.'));

View File

@ -110,7 +110,7 @@ class AuditLogBehavior extends Behavior
'model' => $entity->getSource(),
'model_id' => $id,
'model_title' => $modelTitle,
'change' => $changedFields
'changed' => $changedFields
]);
}
@ -134,7 +134,7 @@ class AuditLogBehavior extends Behavior
'model' => $entity->getSource(),
'model_id' => $this->old->id,
'model_title' => $modelTitle,
'change' => $this->changedFields($entity)
'changed' => $this->changedFields($entity)
]);
}

View File

@ -91,12 +91,12 @@ class AuditLogsTable extends AppTable
$data['model_title'] = mb_substr($data['model_title'], 0, 252) . '...';
}
if (isset($data['change'])) {
$change = json_encode($data['change'], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
if ($this->compressionEnabled && strlen($change) >= self::BROTLI_MIN_LENGTH) {
$change = self::BROTLI_HEADER . brotli_compress($change, 4, BROTLI_TEXT);
if (isset($data['changed'])) {
$changed = json_encode($data['changed'], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
if ($this->compressionEnabled && strlen($changed) >= self::BROTLI_MIN_LENGTH) {
$changed = self::BROTLI_HEADER . brotli_compress($changed, 4, BROTLI_TEXT);
}
$data['change'] = $change;
$data['changed'] = $changed;
}
}

View File

@ -49,9 +49,9 @@ echo $this->element('genericElements/IndexTable/index_table', [
'data_path' => 'request_action',
],
[
'name' => __('Change'),
'sort' => 'change',
'data_path' => 'change',
'name' => __('Changed'),
'sort' => 'changed',
'data_path' => 'changed',
'element' => 'json'
],
],