mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-18 10:35:27 +00:00
(model, migrations) add default migration strategy
This commit is contained in:
parent
6a7262c509
commit
137cac91d5
@ -37,7 +37,27 @@ use Phalcon\Logger\Adapter\Syslog;
|
||||
*/
|
||||
abstract class BaseModelMigration
|
||||
{
|
||||
/**
|
||||
* Walk through all nodes and check required defaults
|
||||
* @param $node
|
||||
*/
|
||||
private function checkDefaults($node)
|
||||
{
|
||||
foreach ($node->__items as $key => $subnode) {
|
||||
if (count($subnode->__items) > 0) {
|
||||
$this->checkDefaults($subnode);
|
||||
} elseif ($subnode->isEmptyAndRequired()) {
|
||||
$subnode->applyDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* default model migration
|
||||
* @param $model
|
||||
*/
|
||||
public function run($model)
|
||||
{
|
||||
$this->checkDefaults($model);
|
||||
}
|
||||
}
|
||||
|
||||
@ -338,7 +338,7 @@ abstract class BaseField
|
||||
* check if this field is unused and required
|
||||
* @return bool
|
||||
*/
|
||||
protected function isEmptyAndRequired()
|
||||
public function isEmptyAndRequired()
|
||||
{
|
||||
if ($this->internalIsRequired && ($this->internalValue == "" || $this->internalValue == null)) {
|
||||
return true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user