Passed
Push — master ( 2c5c47...24e026 )
by Mihail
04:48
created

Apps/Controller/Admin/Main/ActionUpdates.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Apps\Controller\Admin\Main;
4
5
use Apps\Model\Admin\Main\EntityUpdate;
6
use Apps\Model\Admin\Main\FormUpdateDatabase;
7
use Apps\Model\Admin\Main\FormUpdateDownload;
8
use Ffcms\Core\App;
9
use Ffcms\Core\Arch\View;
10
use Ffcms\Core\Network\Request;
11
use Ffcms\Core\Network\Response;
12
13
/**
14
 * Trait ActionUpdates
15
 * @package Apps\Controller\Admin\Main
16
 * @property Request $request
17
 * @property Response $response
18
 * @property View $view
19
 */
20
trait ActionUpdates
21
{
22
    /**
23
     * Make system update
24
     * @return string
25
     * @throws \Ffcms\Core\Exception\SyntaxException
26
     */
27
    public function updates()
28
    {
29
        // initialize models - entity, database, download
30
        $entityModel = new EntityUpdate();
31
        $dbModel = new FormUpdateDatabase($entityModel->dbVersion, $entityModel->scriptVersion);
32
        $downloadModel = new FormUpdateDownload($entityModel->lastInfo['download_url'], $entityModel->lastVersion);
33
34
        // find files with sql queries to update if required
35
        if (!$entityModel->versionsEqual) {
36
            $dbModel->findUpdateFiles();
37
            // if submit is pressed make update
38
            if ($dbModel->send() && $dbModel->validate()) {
39
                $dbModel->make();
40
                App::$Session->getFlashBag()->add('success', __('Database updates are successful installed'));
41
                App::$Response->redirect(Url::to('main/updates'));
0 ignored issues
show
The type Apps\Controller\Admin\Main\Url was not found. Did you mean Url? If so, make sure to prefix the type with \.
Loading history...
42
            }
43
        } elseif ($entityModel->haveRemoteNew) { // download full compiled .zip archive & extract files
44
            if ($downloadModel->send()) {
45
                if ($downloadModel->make()) {
46
                    App::$Session->getFlashBag()->add('success', __('Archive with new update are successful downloaded and extracted. Please refresh this page and update database if required'));
47
                } else {
48
                    App::$Session->getFlashBag()->add('error', __('In process of downloading and extracting update archive error is occurred. Something gonna wrong'));
49
                }
50
            }
51
        }
52
53
        return $this->view->render('updates', [
54
            'entityModel' => $entityModel,
55
            'dbModel' => $dbModel,
56
            'downloadModel' => $downloadModel
57
        ]);
58
    }
59
}
60