Commit 137cac91 authored by Ad Schellevis's avatar Ad Schellevis

(model, migrations) add default migration strategy

parent 6a7262c5
...@@ -37,7 +37,27 @@ use Phalcon\Logger\Adapter\Syslog; ...@@ -37,7 +37,27 @@ use Phalcon\Logger\Adapter\Syslog;
*/ */
abstract class BaseModelMigration 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) public function run($model)
{ {
$this->checkDefaults($model);
} }
} }
...@@ -338,7 +338,7 @@ abstract class BaseField ...@@ -338,7 +338,7 @@ abstract class BaseField
* check if this field is unused and required * check if this field is unused and required
* @return bool * @return bool
*/ */
protected function isEmptyAndRequired() public function isEmptyAndRequired()
{ {
if ($this->internalIsRequired && ($this->internalValue == "" || $this->internalValue == null)) { if ($this->internalIsRequired && ($this->internalValue == "" || $this->internalValue == null)) {
return true; return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment