View file upload/src/addons/AddonsLab/Core/Xf2/AbstractCoreSetup.php

File size: 2.51Kb
<?php
/** 
This software is furnished under a license and may be used and copied
only  in  accordance  with  the  terms  of such  license and with the
inclusion of the above copyright notice.  This software  or any other
copies thereof may not be provided or otherwise made available to any
other person.  No title to and  ownership of the  software is  hereby
transferred.                                                         
                                                                     
You may not reverse  engineer, decompile, defeat  license  encryption
mechanisms, or  disassemble this software product or software product
license.  AddonsLab may terminate this license if you don't comply with
any of these terms and conditions.  In such event,  licensee  agrees 
to return licensor  or destroy  all copies of software  upon termination 
of the license.
*/


namespace AddonsLab\Core\Xf2;

use XF\AddOn\StepRunnerInstallTrait;
use XF\AddOn\StepRunnerUninstallTrait;
use XF\AddOn\StepRunnerUpgradeTrait;

abstract class AbstractCoreSetup extends \XF\AddOn\AbstractSetup
{
    use /** @noinspection TraitsPropertiesConflictsInspection */
        StepRunnerInstallTrait
    {
        install as public _traitInstall;
    }

    use StepRunnerUpgradeTrait
    {
        // access the upgrade method of the trait under another name as we need to override the method ourselves
        upgrade as public _stepUpgrade;
    }

    use StepRunnerUninstallTrait;


    /**
     * Provided by AddonsLab core package, used for automatic creation and synchronization of entity tables
     */
    use SetupTrait;

    public function install(array $stepParams = [])
    {
        $stepParams = array_replace([
            'step' => 0
        ], $stepParams);

        if ($stepParams['step'] === 0)
        {
            // the first step of upgrade, assert entity tables exist and are synced
            $this->_installUpgradeCommon();
        }

        // handle the call to the parent from XF trait
        return $this->_traitInstall($stepParams);
    }

    public function upgrade(array $stepParams = [])
    {
        $stepParams = $this->getStepParams($stepParams);
        if ($stepParams['step'] === 0)
        {
            $this->_installUpgradeCommon();
        }

        // handle the call to the parent from XF trait
        return $this->_stepUpgrade($stepParams);
    }

    protected function _installUpgradeCommon()
    {
        $this->assertCreateTable($this->getCreateMapping());
        $this->assertAlterTable($this->getAlterMapping());
    }
}