public function actionDataProperties() { $data = []; foreach (Property::find()->all() as $item) { $object = Property::getObject($item->class_name); $data[] = ['id' => $item->id, 'var_name' => $object->varName(), 'option_json' => $object->options(), 'label' => $object->label(), 'type' => $object->type(), 'default_value' => $object->defaultValue()]; } return $data; }
public function install() { $model = PropertyModel::find()->where(['var_name' => $this->varName()])->one(); if ($model) { $model->setAttributes(['module_name' => $this->moduleName, 'class_name' => static::className()]); $model->update(false); return $model->id; } else { $model = new PropertyModel(); $model->setAttributes(['var_name' => $this->varName(), 'module_name' => $this->moduleName, 'class_name' => static::className()]); $insert = $model->insert(false); if ($insert) { return $model->id; } } }
public function run() { $ids = []; foreach ($this->getImporter()->getDirectoryFiles('properties') as $file) { $className = $file['ns']; if (class_exists($className)) { $object = Yii::createObject(['class' => $className, 'moduleName' => $file['module']]); if ($object) { $ids[] = $object->install(); $this->getImporter()->addLog('properties', 'Property ' . $object->varName() . ' is installed and up to date.'); } } } foreach (Property::find()->where(['not in', 'id', $ids])->all() as $model) { $this->getImporter()->addLog('properties', 'Removing property (id:' . $model->id . ') ' . $model->var_name); $model->delete(); } }