mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-17 01:54:49 +00:00
(mvc, migrations) remove the need for empty boilerplates by using BaseModelMigration when no custom migration is available for the current version.
This commit is contained in:
parent
8f00c9c7dd
commit
0d4f6eb5ec
@ -241,7 +241,7 @@ abstract class BaseModel
|
||||
$this->internal_mountpoint = $model_xml->mount;
|
||||
|
||||
if (!empty($model_xml->version)) {
|
||||
$this->internal_model_version = $model_xml->version;
|
||||
$this->internal_model_version = (string)$model_xml->version;
|
||||
}
|
||||
|
||||
// use an xpath expression to find the root of our model in the config.xml file
|
||||
@ -537,21 +537,25 @@ abstract class BaseModel
|
||||
$class_info = new \ReflectionClass($this);
|
||||
// fetch version migrations
|
||||
$versions = array();
|
||||
// set default migration for current model version
|
||||
$versions[$this->internal_model_version] =__DIR__."/BaseModelMigration.php";
|
||||
foreach (glob(dirname($class_info->getFileName())."/Migrations/M*.php") as $filename) {
|
||||
$version = str_replace('_', '.', explode('.', substr(basename($filename), 1))[0]);
|
||||
$versions[$version] = $filename;
|
||||
}
|
||||
|
||||
uksort($versions, "version_compare");
|
||||
foreach ($versions as $mig_version => $filename) {
|
||||
if (version_compare($this->internal_current_model_version, $mig_version, '<') &&
|
||||
version_compare($this->internal_model_version, $mig_version, '>=') ) {
|
||||
// execute upgrade action
|
||||
$tmp = explode('.', basename($filename))[0];
|
||||
$mig_classname = "\\".$class_info->getNamespaceName()."\\Migrations\\".$tmp;
|
||||
$mig_classname = explode('.', explode('/mvc/app/models', $filename)[1])[0];
|
||||
$mig_classname = str_replace('/', '\\', $mig_classname);
|
||||
// Phalcon's autoloader uses _ as a directory locator, we need to import these files ourselves
|
||||
require_once $filename;
|
||||
$mig_class = new \ReflectionClass($mig_classname);
|
||||
if ($mig_class->getParentClass()->name == 'OPNsense\Base\BaseModelMigration') {
|
||||
$chk_class = empty($mig_class->getParentClass()) ? $mig_class : $mig_class->getParentClass();
|
||||
if ($chk_class->name == 'OPNsense\Base\BaseModelMigration') {
|
||||
$migobj = $mig_class->newInstance();
|
||||
try {
|
||||
$migobj->run($this);
|
||||
|
||||
@ -35,7 +35,7 @@ use Phalcon\Logger\Adapter\Syslog;
|
||||
/**
|
||||
* @package OPNsense\Base
|
||||
*/
|
||||
abstract class BaseModelMigration
|
||||
class BaseModelMigration
|
||||
{
|
||||
/**
|
||||
* Walk through all nodes and check required defaults
|
||||
|
||||
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2016 Deciso B.V.
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OPNsense\TrafficShaper\Migrations;
|
||||
|
||||
use OPNsense\Base\BaseModelMigration;
|
||||
|
||||
class M1_0_1 extends BaseModelMigration
|
||||
{
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user