예제 #1
0
 private function prepareListenerLogDependantInserts($listener_log_ids)
 {
     $tables = array(ListenerLogProcessError::model()->tableName() => 'log_id', SensorData::model()->tableName() => 'listener_log_id', SensorDataMinute::model()->tableName() => 'listener_log_id', SeaLevelTrend::model()->tableName() => 'log_id', StationCalculationData::model()->tableName() => 'listener_log_id');
     $result_sql = array();
     foreach ($tables as $table => $log_id_field) {
         $sql = "SELECT * \n                    FROM `" . $table . "`\n                    WHERE `" . $log_id_field . "` IN (" . implode(',', $listener_log_ids) . ")";
         $res = Yii::app()->db->createCommand($sql)->queryAll();
         $total = count($res);
         if ($res) {
             $fields = array();
             foreach ($res[0] as $key2 => $value2) {
                 $fields[] = $key2;
             }
             $sql_header = "INSERT IGNORE INTO `" . $table . "` (`" . implode('`,`', $fields) . "`) VALUES ";
             $res_sql = $sql_header;
             $cnt = 0;
             foreach ($res as $key => $value) {
                 $res_sql .= "('" . implode("','", $value) . "')";
                 if ($key + 1 < $total) {
                     $res_sql .= ", ";
                 }
                 $cnt++;
             }
             $result_sql[] = $res_sql;
             $this->addBackupLog("Prepared " . $cnt . " inserts for " . $table);
         }
     }
     return $result_sql;
 }
예제 #2
0
 public function prepareList($page_size = 50)
 {
     $sql_where_str = $this->_prepareSqlCondition();
     $sql_order_str = $this->_prepareSqlOrder();
     if ($page_size) {
         $total = $this->total;
     }
     if ($total || !$page_size) {
         if ($page_size) {
             $pages = new CPagination($total);
             $pages->pageSize = $page_size;
         }
         $sql = "SELECT `t1`.`log_id`, `t1`.`updated`,`t1`.`measuring_timestamp`, `t1`.`created`, `t1`.`message`, `t1`.`fail_description`, t3.station_id_code, t3.display_name, t3.station_type, `t2`.`process_error_id`, `t1`.`is_processed`\n                    FROM `" . ListenerLog::model()->tableName() . "` t1\n                    LEFT JOIN `" . ListenerLogProcessError::model()->tableName() . "` `t2` ON `t2`.`log_id` = `t1`.`log_id`\n                    LEFT JOIN `" . Station::model()->tableName() . "` `t3` ON `t3`.`station_id` = `t1`.`station_id`\n                    {$sql_where_str}\n                    GROUP BY `t1`.`log_id`\n                    {$sql_order_str}";
         if ($page_size) {
             $sql .= " LIMIT " . $pages->currentPage * $pages->pageSize . ", " . $pages->pageSize;
         }
         $res = CStubActiveRecord::getDbConnect(true)->createCommand($sql)->queryAll();
         if ($res) {
             $ids = array();
             foreach ($res as $key => $value) {
                 $ids[] = $value['log_id'];
                 if ($value['fail_description']) {
                     $value['errors'] = explode(',', $value['fail_description']);
                 }
                 $list[$value['log_id']] = $value;
             }
             $sql = "SELECT * FROM `" . ListenerLogProcessError::model()->tableName() . "` WHERE `log_id` IN (" . implode(',', $ids) . ")";
             $res2 = CStubActiveRecord::getDbConnect(true)->createCommand($sql)->queryAll();
             if ($res2) {
                 foreach ($res2 as $key => $value) {
                     if ($value['type'] == 'error') {
                         $list[$value['log_id']]['errors'][] = $value['description'];
                     } else {
                         if ($value['type'] == 'warning') {
                             $list[$value['log_id']]['warnings'][] = $value['description'];
                         }
                     }
                 }
             }
         }
     }
     return array('list' => $list, 'pages' => $pages);
 }