/** * Execute the action. * @param array command line parameters specific for this command */ public function actionIndex($type = 'roomNames', $testWord = '') { if ($type == 'roomNames') { $connection = Yii::app()->db; $command = $connection->createCommand("SELECT * FROM room_names_nemo"); echo "Memory usage: {peak:" . ceil(memory_get_peak_usage() / 1024) . "kb , now: " . ceil(memory_get_usage() / 1024) . "kb }\n"; $dataReader = $command->query(); echo "Memory usage: {peak:" . ceil(memory_get_peak_usage() / 1024) . "kb , now: " . ceil(memory_get_usage() / 1024) . "kb }\n"; $i = 0; while (($row = $dataReader->read()) !== false) { //CVarDumper::dump($row); /*echo "{"; foreach($row as $key=>$val){ echo "$key : $val ,"; } echo "}\n";*/ $roomInfo = HotelRoom::parseRoomNameStatic($row['roomNameCanonical']); $sql = 'SELECT * FROM room_names_nemo WHERE '; $conductions = array(); foreach ($row as $key => $val) { if ($val) { $conductions[$key] = "{$key} = '{$val}'"; } else { $conductions[$key] = "{$key} IS NULL"; } } $conductions['id'] = "id != {$row['id']}"; $conductions['roomNameCanonical'] = "roomNameCanonical = '" . addslashes($roomInfo['roomNameCanonical']) . "'"; unset($conductions['roomNameRusId']); $sql .= join(' AND ', $conductions); //echo "sql: {$sql}\n"; $commandFind = $connection->createCommand($sql); $findRow = $commandFind->queryRow(); if ($findRow) { echo "{"; foreach ($findRow as $key => $val) { echo "{$key} : {$val} ,"; } echo "}\n"; } $roomName = new RoomNamesNemo(); $roomName->setAttributes($row); if ($findRow) { if ($findRow['roomNameRusId']) { $roomName->roomNameRusId = $findRow['roomNameRusId']; } $count = $connection->createCommand("DELETE FROM room_names_nemo WHERE id = {$findRow['id']}")->execute(); if (!$count) { echo "Cant delete" . "DELETE FROM room_names_nemo WHERE id = {$findRow['id']} \n"; } } unset($findRow); unset($commandFind); $roomName->roomNameCanonical = $roomInfo['roomNameCanonical']; $roomName->id = $row['id']; $roomName->setIsNewRecord(false); $roomName->save(); unset($roomName); unset($sql); unset($roomInfo); if ($i % 100 == 0) { echo "Memory usage: {peak:" . ceil(memory_get_peak_usage() / 1024) . "kb , now: " . ceil(memory_get_usage() / 1024) . "kb }\n"; //break; } $i++; } echo "Memory usage: {peak:" . ceil(memory_get_peak_usage() / 1024) . "kb , now: " . ceil(memory_get_usage() / 1024) . "kb }\n"; } elseif ($type == 'testRoomNames') { CVarDumper::dump(HotelRoom::parseRoomNameStatic($testWord)); } }
public function actionDelete($id) { $roomNameRus = RoomNamesRus::model()->findByPk($id); if ($roomNameRus) { $criteria = new CDbCriteria(); $criteria->addCondition('roomNameRusId = :rnri'); $criteria->params = array(':rnri' => $id); RoomNamesNemo::model()->updateAll(array('roomNameRusId' => null), $criteria); $roomNameRus->delete(); $this->redirect('/admin/hotels/roomNames/rusNamesManage'); } else { echo "Элемента не найдено!"; } }
public function fillValues() { if (self::$needLoading) { $in = array(); $startTime = microtime(true); foreach (self::$lazyLoadObjectsIds as $arrayId) { $roomName =& self::$roomNames[$arrayId]; $queryLine = "(" . ($roomName->roomTypeId ? $roomName->roomTypeId : 'NULL') . "," . ($roomName->roomSizeId ? $roomName->roomSizeId : 'NULL') . "," . ($roomName->roomNameCanonical ? "'" . addslashes($roomName->roomNameCanonical) . "'" : "''") . ")"; $in[] = $queryLine; } $connection = Yii::app()->db; $sql = 'SELECT room_names_nemo.id,roomTypeId,roomSizeId,roomNameCanonical,roomNameRusId,room_names_rus.roomNameRus as roomNameRus FROM room_names_nemo LEFT JOIN room_names_rus ON room_names_nemo.roomNameRusId = room_names_rus.id WHERE (roomTypeId,roomSizeId,roomNameCanonical) IN'; $sql .= " (" . implode(',', $in) . ")"; $command = $connection->createCommand($sql); $dataReader = $command->query(); $i = 0; while (($row = $dataReader->read()) !== false) { $i++; $roomNameCanonical = $row['roomNameCanonical']; $roomSizeId = $row['roomSizeId']; $roomTypeId = $row['roomTypeId']; $roomParamsKey = ($roomNameCanonical ? $roomNameCanonical : '') . '|' . ($roomSizeId ? $roomSizeId : '') . '|' . ($roomTypeId ? $roomTypeId : ''); self::$roomNames[self::$paramsIdMap[$roomParamsKey]]->id = $row['id']; self::$roomNames[self::$paramsIdMap[$roomParamsKey]]->setIsNewRecord(false); unset(self::$lazyLoadObjectsIds[self::$paramsIdMap[$roomParamsKey]]); if ($row['roomNameRus']) { RoomNamesRus::$roomNamesRus[$row['roomNameRusId']] = new RoomNamesRus(); RoomNamesRus::$roomNamesRus[$row['roomNameRusId']]->id = $row['roomNameRusId']; RoomNamesRus::$roomNamesRus[$row['roomNameRusId']]->roomNameRus = $row['roomNameRus']; } } $endTime = microtime(true); $fullTime = $endTime - $startTime; //header('FullSQLTime: '.$i.'|'.$fullTime); $startTime = microtime(true); self::$needLoading = false; $i = 0; foreach (self::$lazyLoadObjectsIds as $arrayId) { self::$roomNames[$arrayId]->save(); $i++; } $endTime = microtime(true); $fullTime = $endTime - $startTime; //header('Saving'.$i.'Objs: '.$fullTime); } }