public function actionChain() { \yii::$app->user->setIdentity(\common\models\User::findByUsername('admin')); $usersData = \yii::$app->oldcmsdb->createCommand("SELECT * FROM tc_est_groups")->query(); while ($row = $usersData->read()) { $attributes = array('Id' => $row['est_grp_id'], 'name' => htmlspecialchars_decode($row['est_grp_name'], ENT_QUOTES), 'description' => htmlspecialchars_decode($row['est_grp_desc'], ENT_QUOTES), 'guid' => $row['est_grp_url'], 'status' => $row['status'], 'ip' => $row['IP'], 'createdOn' => $row['insertdate'], 'updatedOn' => $row['insertdate'], 'createdBy' => 40, 'updatedBy' => 40); if (($brand = Brands::findOne($attributes['Id'])) !== null) { } else { $brand = new Brands(); } $attributes['logo'] = $this->importimagefromstr($row['logo'], $brand->logoPath, 'chainLogo'); $chainImage = \yii::$app->oldcmsdb->createCommand("select * from tc_est_media where est_flag = 'chainMainImage' and est_id='" . $row['est_grp_id'] . "' and status=1 order by est_priority")->query(); $images = []; while ($img = $chainImage->read()) { $images[] = ['media_id' => $img['est_media_id'], 'media_name' => $img['est_media_name'], 'media_caption' => $img['est_media_caption'], 'flag' => $img['est_flag'], 'created_by' => $img['created_by'], 'insertdate' => $img['insertdate'], 'IP' => $img['IP'], 'priority' => $img['est_priority']]; } $attributes['media'] = Import::importMediaData($images, $brand->imagePath); $chainmenu = \yii::$app->oldcmsdb->createCommand("select * from tc_est_media where est_flag = 'chainMainMenu' and est_id='" . $row['est_grp_id'] . "' and status=1 order by est_priority")->query(); $images = []; while ($img = $chainmenu->read()) { $images[] = ['media_id' => $img['est_media_id'], 'media_name' => $img['est_media_name'], 'media_caption' => $img['est_media_caption'], 'flag' => $img['est_flag'], 'created_by' => $img['created_by'], 'insertdate' => $img['insertdate'], 'IP' => $img['IP'], 'priority' => $img['est_priority']]; } $attributes['menu'] = Import::importMediaData($images, $brand->menuimagePath); $brand->detachBehavior('timestamp'); $brand->detachBehavior('user'); $brand->setAttributes($attributes); $brand->Id = $attributes['Id']; if ($brand->save(false, null, $attributes)) { echo "Chain Id:" . $attributes['Id'] . " name:" . $attributes['name'] . ": imported\n"; } else { echo "Chain Id:" . $attributes['Id'] . " name:" . $attributes['name'] . ": not imported\n"; } } }
/** * Finds the Brands model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Brands the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Brands::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }