| Conditions | 5 |
| Paths | 5 |
| Total Lines | 31 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| 1 | <?php |
||
| 11 | public function up() |
||
| 12 | { |
||
| 13 | $products = Product::findAll(['parent_id' => 0]); |
||
| 14 | foreach ($products as $product) { |
||
| 15 | $object = Object::getForClass(Product::className()); |
||
| 16 | $gid = Json::decode($product->option_generate)['group']; |
||
| 17 | $cid = Product::findAll(['parent_id' => $product->id]); |
||
| 18 | foreach ($cid as $subProduct) { |
||
| 19 | $q = ObjectPropertyGroup::findAll( |
||
| 20 | 'object_model_id = :object_model_id and object_id = :object_id and property_group_id = :property_group_id', |
||
| 21 | [ |
||
| 22 | 'object_model_id' => $subProduct->id, |
||
| 23 | 'object_id' => $object->id, |
||
| 24 | 'property_group_id' => $gid |
||
| 25 | ] |
||
| 26 | ); |
||
| 27 | if (count($q) === 0) { |
||
| 28 | $opg = new ObjectPropertyGroup(); |
||
| 29 | $opg->object_id = $object->id; |
||
| 30 | $opg->object_model_id = $subProduct->id; |
||
| 31 | $opg->property_group_id = $gid; |
||
| 32 | if ($opg->save()) { |
||
| 33 | echo 'Insert: ' . $opg->object_model_id . ' with property_group_id = ' . $opg->property_group_id . "\n"; |
||
| 34 | } else { |
||
| 35 | echo 'Insert error' . "\n"; |
||
| 36 | print_r($opg->getErrors()); |
||
| 37 | } |
||
| 38 | } |
||
| 39 | } |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 49 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.