2020-06-21 21:29:25 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
|
|
use App\Controller\AppController;
|
|
|
|
use Cake\Utility\Hash;
|
|
|
|
use Cake\Utility\Text;
|
|
|
|
use \Cake\Database\Expression\QueryExpression;
|
2021-02-24 11:05:23 +01:00
|
|
|
use Cake\Event\EventInterface;
|
2020-06-21 21:29:25 +02:00
|
|
|
|
|
|
|
class InstanceController extends AppController
|
|
|
|
{
|
2021-02-24 11:05:23 +01:00
|
|
|
public function beforeFilter(EventInterface $event)
|
|
|
|
{
|
|
|
|
parent::beforeFilter($event);
|
|
|
|
$this->set('metaGroup', !empty($this->isAdmin) ? 'Cerebrate' : 'Administration');
|
|
|
|
}
|
|
|
|
|
2020-06-21 21:29:25 +02:00
|
|
|
public function home()
|
|
|
|
{
|
2020-06-22 14:28:17 +02:00
|
|
|
$this->set('md', file_get_contents(ROOT . '/README.md'));
|
2020-06-21 21:29:25 +02:00
|
|
|
}
|
2020-09-29 13:20:33 +02:00
|
|
|
|
|
|
|
public function status()
|
|
|
|
{
|
|
|
|
$data = file_get_contents(APP . 'VERSION.json');
|
|
|
|
$data = json_decode($data, true);
|
|
|
|
$data['user'] = $this->ACL->getUser();
|
|
|
|
return $this->RestResponse->viewData($data, 'json');
|
|
|
|
}
|
2021-02-24 11:05:23 +01:00
|
|
|
|
|
|
|
public function migrationIndex()
|
|
|
|
{
|
|
|
|
$migrationStatus = $this->Instance->getMigrationStatus();
|
|
|
|
|
|
|
|
$this->loadModel('Phinxlog');
|
|
|
|
$status = $this->Phinxlog->mergeMigrationLogIntoStatus($migrationStatus['status']);
|
|
|
|
|
|
|
|
$this->set('status', $status);
|
|
|
|
$this->set('updateAvailables', $migrationStatus['updateAvailables']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function migrate($version=null) {
|
|
|
|
if ($this->request->is('post')) {
|
|
|
|
if (is_null($version)) {
|
|
|
|
$migrateResult = $this->Instance->migrate();
|
|
|
|
} else {
|
|
|
|
$migrateResult = $this->Instance->migrate(['target' => $version]);
|
|
|
|
}
|
|
|
|
if ($this->ParamHandler->isRest() || $this->ParamHandler->isAjax()) {
|
|
|
|
if ($migrateResult['success']) {
|
|
|
|
return $this->RestResponse->saveSuccessResponse('instance', 'migrate', false, false, __('Migration sucessful'));
|
|
|
|
} else {
|
|
|
|
return $this->RestResponse->saveFailResponse('instance', 'migrate', false, $migrateResult['error']);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($migrateResult['success']) {
|
|
|
|
$this->Flash->success(__('Migration sucessful'));
|
|
|
|
$this->redirect(['action' => 'migrationIndex']);
|
|
|
|
} else {
|
|
|
|
$this->Flash->error(__('Migration fail'));
|
|
|
|
$this->redirect(['action' => 'migrationIndex']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$migrationStatus = $this->Instance->getMigrationStatus();
|
|
|
|
$this->set('title', __n('Run database update?', 'Run all database updates?', count($migrationStatus['updateAvailables'])));
|
|
|
|
$this->set('question', __('The process might take some time.'));
|
|
|
|
$this->set('actionName', __n('Run update', 'Run all updates', count($migrationStatus['updateAvailables'])));
|
|
|
|
$this->set('path', ['controller' => 'instance', 'action' => 'migrate']);
|
|
|
|
$this->render('/genericTemplates/confirm');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function rollback($version=null) {
|
|
|
|
if ($this->request->is('post')) {
|
|
|
|
if (is_null($version)) {
|
|
|
|
$migrateResult = $this->Instance->rollback();
|
|
|
|
} else {
|
|
|
|
$migrateResult = $this->Instance->rollback(['target' => $version]);
|
|
|
|
}
|
|
|
|
if ($this->ParamHandler->isRest() || $this->ParamHandler->isAjax()) {
|
|
|
|
if ($migrateResult['success']) {
|
|
|
|
return $this->RestResponse->saveSuccessResponse('instance', 'rollback', false, false, __('Rollback sucessful'));
|
|
|
|
} else {
|
|
|
|
return $this->RestResponse->saveFailResponse('instance', 'rollback', false, $migrateResult['error']);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($migrateResult['success']) {
|
|
|
|
$this->Flash->success(__('Rollback sucessful'));
|
|
|
|
$this->redirect(['action' => 'migrationIndex']);
|
|
|
|
} else {
|
|
|
|
$this->Flash->error(__('Rollback fail'));
|
|
|
|
$this->redirect(['action' => 'migrationIndex']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$migrationStatus = $this->Instance->getMigrationStatus();
|
|
|
|
$this->set('title', __('Run database rollback?'));
|
|
|
|
$this->set('question', __('The process might take some time.'));
|
|
|
|
$this->set('actionName', __('Run rollback'));
|
|
|
|
$this->set('path', ['controller' => 'instance', 'action' => 'rollback']);
|
|
|
|
$this->render('/genericTemplates/confirm');
|
|
|
|
}
|
2021-07-19 15:00:09 +02:00
|
|
|
|
|
|
|
public function settings()
|
|
|
|
{
|
|
|
|
$this->Settings = $this->getTableLocator()->get('Settings');
|
2021-07-20 11:54:55 +02:00
|
|
|
$all = $this->Settings->getSettings(true);
|
2021-07-19 15:00:09 +02:00
|
|
|
$this->set('settingsProvider', $all['settingsProvider']);
|
|
|
|
$this->set('settings', $all['settings']);
|
2021-07-20 11:54:55 +02:00
|
|
|
$this->set('notices', $all['notices']);
|
2021-07-19 15:00:09 +02:00
|
|
|
}
|
2020-06-21 21:29:25 +02:00
|
|
|
}
|