chg: [app] Added timestamp behavior for multiple models
parent
8b5d2bc48a
commit
348792c815
|
@ -0,0 +1,124 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
|
||||||
|
class TimestampBehavior extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function change()
|
||||||
|
{
|
||||||
|
$alignments = $this->table('alignments')
|
||||||
|
->addColumn('created', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->addColumn('modified', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->update();
|
||||||
|
|
||||||
|
$broods = $this->table('broods')
|
||||||
|
->addColumn('created', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->addColumn('modified', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->update();
|
||||||
|
|
||||||
|
$encryption_keys = $this->table('encryption_keys')
|
||||||
|
->addColumn('created', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->addColumn('modified', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->update();
|
||||||
|
|
||||||
|
$inbox = $this->table('inbox')
|
||||||
|
->addColumn('modified', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->update();
|
||||||
|
|
||||||
|
$outbox = $this->table('outbox')
|
||||||
|
->addColumn('modified', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->update();
|
||||||
|
|
||||||
|
$individuals = $this->table('individuals')
|
||||||
|
->addColumn('created', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->addColumn('modified', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->update();
|
||||||
|
|
||||||
|
$local_tools = $this->table('local_tools')
|
||||||
|
->addColumn('created', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->addColumn('modified', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->update();
|
||||||
|
|
||||||
|
$meta_templates = $this->table('meta_templates')
|
||||||
|
->addColumn('created', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->addColumn('modified', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->update();
|
||||||
|
|
||||||
|
$organisations = $this->table('organisations')
|
||||||
|
->addColumn('created', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->addColumn('modified', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->update();
|
||||||
|
|
||||||
|
$sharing_groups = $this->table('sharing_groups')
|
||||||
|
->addColumn('created', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->addColumn('modified', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->update();
|
||||||
|
|
||||||
|
$users = $this->table('users')
|
||||||
|
->addColumn('created', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->addColumn('modified', 'datetime', [
|
||||||
|
'default' => null,
|
||||||
|
'null' => false,
|
||||||
|
])
|
||||||
|
->update();
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
use App\Controller\AppController;
|
use App\Controller\AppController;
|
||||||
|
use Cake\Utility\Inflector;
|
||||||
use Cake\Utility\Hash;
|
use Cake\Utility\Hash;
|
||||||
use Cake\Utility\Text;
|
use Cake\Utility\Text;
|
||||||
use \Cake\Database\Expression\QueryExpression;
|
use \Cake\Database\Expression\QueryExpression;
|
||||||
|
@ -58,6 +59,16 @@ class InstanceController extends AppController
|
||||||
$this->loadModel('Phinxlog');
|
$this->loadModel('Phinxlog');
|
||||||
$status = $this->Phinxlog->mergeMigrationLogIntoStatus($migrationStatus['status']);
|
$status = $this->Phinxlog->mergeMigrationLogIntoStatus($migrationStatus['status']);
|
||||||
|
|
||||||
|
foreach ($status as $i => $entry) {
|
||||||
|
if (!empty($entry['plugin'])) {
|
||||||
|
$pluginTablename = sprintf('%s_phinxlog', Inflector::underscore($entry['plugin']));
|
||||||
|
$status[$i] = $this->Phinxlog->mergeMigrationLogIntoStatus([$entry], $pluginTablename)[0];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
usort($status, function($a, $b) {
|
||||||
|
return strcmp($b['id'], $a['id']);
|
||||||
|
});
|
||||||
$this->set('status', $status);
|
$this->set('status', $status);
|
||||||
$this->set('updateAvailables', $migrationStatus['updateAvailables']);
|
$this->set('updateAvailables', $migrationStatus['updateAvailables']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ class AlignmentsTable extends AppTable
|
||||||
parent::initialize($config);
|
parent::initialize($config);
|
||||||
$this->belongsTo('Individuals');
|
$this->belongsTo('Individuals');
|
||||||
$this->belongsTo('Organisations');
|
$this->belongsTo('Organisations');
|
||||||
|
$this->addBehavior('Timestamp');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validationDefault(Validator $validator): Validator
|
public function validationDefault(Validator $validator): Validator
|
||||||
|
|
|
@ -18,6 +18,7 @@ class BroodsTable extends AppTable
|
||||||
{
|
{
|
||||||
parent::initialize($config);
|
parent::initialize($config);
|
||||||
$this->addBehavior('UUID');
|
$this->addBehavior('UUID');
|
||||||
|
$this->addBehavior('Timestamp');
|
||||||
$this->BelongsTo(
|
$this->BelongsTo(
|
||||||
'Organisations'
|
'Organisations'
|
||||||
);
|
);
|
||||||
|
|
|
@ -14,6 +14,7 @@ class EncryptionKeysTable extends AppTable
|
||||||
{
|
{
|
||||||
parent::initialize($config);
|
parent::initialize($config);
|
||||||
$this->addBehavior('UUID');
|
$this->addBehavior('UUID');
|
||||||
|
$this->addBehavior('Timestamp');
|
||||||
$this->belongsTo(
|
$this->belongsTo(
|
||||||
'Individuals',
|
'Individuals',
|
||||||
[
|
[
|
||||||
|
|
|
@ -14,6 +14,7 @@ class IndividualsTable extends AppTable
|
||||||
{
|
{
|
||||||
parent::initialize($config);
|
parent::initialize($config);
|
||||||
$this->addBehavior('UUID');
|
$this->addBehavior('UUID');
|
||||||
|
$this->addBehavior('Timestamp');
|
||||||
$this->addBehavior('Tags.Tag');
|
$this->addBehavior('Tags.Tag');
|
||||||
$this->hasMany(
|
$this->hasMany(
|
||||||
'Alignments',
|
'Alignments',
|
||||||
|
|
|
@ -27,7 +27,7 @@ class InstanceTable extends AppTable
|
||||||
|
|
||||||
public function getStatistics($days=30): array
|
public function getStatistics($days=30): array
|
||||||
{
|
{
|
||||||
$models = ['Individuals', 'Organisations', 'Alignments', 'EncryptionKeys', 'SharingGroups', 'Users', 'Tags.Tags'];
|
$models = ['Individuals', 'Organisations', 'Alignments', 'EncryptionKeys', 'SharingGroups', 'Users', 'Broods', 'Tags.Tags'];
|
||||||
foreach ($models as $model) {
|
foreach ($models as $model) {
|
||||||
$table = TableRegistry::getTableLocator()->get($model);
|
$table = TableRegistry::getTableLocator()->get($model);
|
||||||
$statistics[$model]['amount'] = $table->find()->all()->count();
|
$statistics[$model]['amount'] = $table->find()->all()->count();
|
||||||
|
|
|
@ -30,6 +30,7 @@ class LocalToolsTable extends AppTable
|
||||||
public function initialize(array $config): void
|
public function initialize(array $config): void
|
||||||
{
|
{
|
||||||
parent::initialize($config);
|
parent::initialize($config);
|
||||||
|
$this->addBehavior('Timestamp');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validationDefault(Validator $validator): Validator
|
public function validationDefault(Validator $validator): Validator
|
||||||
|
|
|
@ -13,6 +13,7 @@ class MetaTemplatesTable extends AppTable
|
||||||
public function initialize(array $config): void
|
public function initialize(array $config): void
|
||||||
{
|
{
|
||||||
parent::initialize($config);
|
parent::initialize($config);
|
||||||
|
$this->addBehavior('Timestamp');
|
||||||
$this->hasMany(
|
$this->hasMany(
|
||||||
'MetaTemplateFields',
|
'MetaTemplateFields',
|
||||||
[
|
[
|
||||||
|
|
|
@ -18,6 +18,7 @@ class OrganisationsTable extends AppTable
|
||||||
public function initialize(array $config): void
|
public function initialize(array $config): void
|
||||||
{
|
{
|
||||||
parent::initialize($config);
|
parent::initialize($config);
|
||||||
|
$this->addBehavior('Timestamp');
|
||||||
$this->addBehavior('Tags.Tag');
|
$this->addBehavior('Tags.Tag');
|
||||||
$this->hasMany(
|
$this->hasMany(
|
||||||
'Alignments',
|
'Alignments',
|
||||||
|
|
|
@ -12,8 +12,11 @@ class PhinxlogTable extends AppTable
|
||||||
parent::initialize($config);
|
parent::initialize($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function mergeMigrationLogIntoStatus(array $status): array
|
public function mergeMigrationLogIntoStatus(array $status, $table=null): array
|
||||||
{
|
{
|
||||||
|
if (!is_null($table)) {
|
||||||
|
$this->setTable($table);
|
||||||
|
}
|
||||||
$logs = $this->find('list', [
|
$logs = $this->find('list', [
|
||||||
'keyField' => 'version',
|
'keyField' => 'version',
|
||||||
'valueField' => function ($entry) {
|
'valueField' => function ($entry) {
|
||||||
|
|
|
@ -14,6 +14,7 @@ class SharingGroupsTable extends AppTable
|
||||||
{
|
{
|
||||||
parent::initialize($config);
|
parent::initialize($config);
|
||||||
$this->addBehavior('UUID');
|
$this->addBehavior('UUID');
|
||||||
|
$this->addBehavior('Timestamp');
|
||||||
$this->belongsTo(
|
$this->belongsTo(
|
||||||
'Users'
|
'Users'
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue