<?php

namespace ThurData\Servers\KerioEmail\Core\Configuration\Addon\Update\Patch;

use ThurData\Servers\KerioEmail\Core\Helper\DatabaseHelper;
use ThurData\Servers\KerioEmail\Core\ModuleConstants;

/**
 * Description of AbstractPatch
 *
 * @autor ThurData <info@thurdata.ch>
 */
class AbstractPatch
{
    /**
     * @var DatabaseHelper 
     */
    protected $databaseHelper;

    /**
     * @var string
     */
    private $path;

    /**
     * @var string
     */
    private $versionName;

    protected $version;

    /**
     * @param DatabaseHelper $databaseHelper
     */
    public function __construct(DatabaseHelper $databaseHelper)
    {
        $this->databaseHelper = $databaseHelper;
        $this->path = ModuleConstants::getModuleRootDir() . DS . 'app' . DS . 'Database';
        $this->versionName = end(explode("\\",get_called_class()));
    }

    /**
     * @return bool
     */
    protected function runSchema()
    {
        return ($this->databaseHelper->performQueryFromFile($this->path . DS . $this->versionName . DS . 'schema.sql') === true)
                ?false
                :true;
    }

    /**
     * @return bool
     */
    protected function runData()
    {
        return ($this->databaseHelper->performQueryFromFile($this->path . DS . $this->versionName . DS . 'data.sql') === true)
                ?false
                :true;
    }

    public function setVersion($version = null)
    {
        $this->version = $version;

        return $this;
    }

    public function getVersion()
    {
        return $this->version;
    }

    public function execute()
    {
        
    }
}
