public function actionConvert() { @set_time_limit(0); @ini_set('max_execution_time', 0); $sql = 'SELECT id, owner_id FROM {{apartment}} WHERE 1'; $res = Yii::app()->db->createCommand($sql)->queryAll(); $ids = CHtml::listData($res, 'id', 'owner_id'); $sql = 'SELECT pid, imgsOrder FROM {{galleries}} WHERE 1'; $res = Yii::app()->db->createCommand($sql)->queryAll(); if ($res) { foreach ($res as $item) { $images = unserialize($item['imgsOrder']); if (!isset($ids[$item['pid']])) { continue; } if ($images) { $cnt = 0; foreach ($images as $image => $name) { $filePath = Yii::getPathOfAlias('webroot.uploads.apartments.' . $item['pid'] . '.pictures') . '/' . $image; Images::addImage($filePath, $item['pid'], $cnt == 0, $ids[$item['pid']]); $cnt++; } } } } }
public function actionConvert() { @set_time_limit(0); @ini_set('max_execution_time', 0); @ini_set('gd.jpeg_ignore_warning', 1); $limit = 200; $data = Yii::app()->statePersister->load(); $lastImportId = isset($data['last_import_id']) ? $data['last_import_id'] : 0; $sql = 'SELECT id, owner_id FROM {{apartment}} WHERE id > ' . $lastImportId . ' LIMIT ' . $limit; $res = Yii::app()->db->createCommand($sql)->queryAll(); $ids = CHtml::listData($res, 'id', 'owner_id'); $sql = 'SELECT pid, imgsOrder FROM {{galleries}} WHERE pid > ' . $lastImportId . ' LIMIT ' . $limit; $res = Yii::app()->db->createCommand($sql)->queryAll(); $i = 0; if ($res) { foreach ($res as $item) { $images = unserialize($item['imgsOrder']); if (!isset($ids[$item['pid']])) { continue; } if ($images) { $cnt = 0; foreach ($images as $image => $name) { $filePath = Yii::getPathOfAlias('webroot.uploads.apartments.' . $item['pid'] . '.pictures') . '/' . $image; try { Images::addImage($filePath, $item['pid'], $cnt == 0, $ids[$item['pid']]); } catch (Exception $e) { echo '<b>Выброшено исключение: ', $e->getMessage(), "\n</b><br>"; } $cnt++; } } $data['last_import_id'] = $item['pid']; Yii::app()->statePersister->save($data); $i++; if ($i >= $limit) { break; } } } echo 'Converted ' . $i . ' ads'; }