Beispiel #1
0
 /**
  * Saves indexable attributes from data array.
  *
  * @param array $data
  * @return bool whether the attributes were saved
  */
 public static function saveFromData($data)
 {
     list($indexableCondition, $deleteCondition) = self::getConditions($data);
     $indexableAttributes = IndexAttribute::find()->where($indexableCondition)->all();
     foreach ($data as $item) {
         if ($item['indexable']) {
             $indexable = false;
             foreach ($indexableAttributes as $indexableItem) {
                 if ($item['index_type'] === $indexableItem['index_type'] && $item['name'] === $indexableItem['name']) {
                     $indexableItem->load($item);
                     $indexable = true;
                     break;
                 }
             }
             if (!$indexable) {
                 $indexableAttributes[] = new IndexAttribute($item);
             }
         }
     }
     $saved = true;
     foreach ($indexableAttributes as $item) {
         if (!$item->save()) {
             $saved = false;
         }
     }
     if ($saved) {
         IndexAttribute::deleteAll($deleteCondition);
     }
     return $saved;
 }