cerebrate/src/Model/Table/InstanceTable.php

61 lines
1.5 KiB
PHP
Raw Normal View History

2020-06-21 21:29:25 +02:00
<?php
namespace App\Model\Table;
use App\Model\Table\AppTable;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use Migrations\Migrations;
2020-06-21 21:29:25 +02:00
class InstanceTable extends AppTable
{
public function initialize(array $config): void
{
parent::initialize($config);
}
public function validationDefault(Validator $validator): Validator
{
return $validator;
}
public function getMigrationStatus()
{
$migrations = new Migrations();
$status = $migrations->status();
$status = array_reverse($status);
$updateAvailables = array_filter($status, function ($update) {
return $update['status'] != 'up';
});
return [
'status' => $status,
'updateAvailables' => $updateAvailables,
];
}
public function migrate($version=null) {
$migrations = new Migrations();
if (is_null($version)) {
$migrationResult = $migrations->migrate();
} else {
$migrationResult = $migrations->migrate(['target' => $version]);
}
return [
'success' => true
];
}
public function rollback($version=null) {
$migrations = new Migrations();
if (is_null($version)) {
$migrationResult = $migrations->rollback();
} else {
$migrationResult = $migrations->rollback(['target' => $version]);
}
return [
'success' => true
];
}
2020-06-21 21:29:25 +02:00
}