public function afterDelete() { if (!$this->getUseLong()) { ScheduleReportProcessed::model()->deleteAllByAttributes(array('listener_log_id' => $this->log_id)); } parent::afterDelete(); }
public function __construct($scheduleProcessedIdArray = array(), $logger = null) { if (!is_null($logger)) { $this->_logger = $logger; } else { $this->_logger = LoggerFactory::getFileLogger('email_report'); } $this->_logger->log(__METHOD__ . ' schedule_processed_ids: ' . print_r($scheduleProcessedIdArray, 1)); if (count($scheduleProcessedIdArray) == 0) { return false; } $this->scheduleProcessedReports = ScheduleReportProcessed::model()->with('listenerLog', 'ScheduleReportToStation.realStation')->findAllByPk($scheduleProcessedIdArray); $this->schedule_report = $this->scheduleProcessedReports[0]->ScheduleReportToStation->schedule_report; if (!$this->schedule_report->send_email_together) { return false; } $this->destinations = $this->scheduleProcessedReports[0]->ScheduleReportToStation->schedule_report->destinations; if ($this->schedule_report->send_like_attach) { $this->_sendLikeAttach(); } else { $this->_sendInMessageBody(); } }
public function saveProcess() { $this->_logger->log(__METHOD__); $string = $this->getReportComplete(); $obj = ScheduleReportProcessed::model()->findByPk($this->_schedule_processed_id); $obj->is_processed = 1; $obj->serialized_report_errors = serialize($this->errors); $obj->serialized_report_explanations = serialize($this->explanations); $obj->save(); $file_path = $this->tmpReportFile(); }
public function actionScheduleDownload() { $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null; $process = ScheduleReportProcessed::model()->with('ScheduleReportToStation.realStation')->with('ScheduleReportToStation.schedule_report')->findByPk($id); if (!$process) { $this->redirect($_SERVER['HTTP_REFERER']); } $station = $process->ScheduleReportToStation->realStation; $schedule = $process->ScheduleReportToStation->schedule_report; $file_name = $station->station_id_code . '_' . strtoupper($schedule->report_type) . '_' . gmdate('Y-m-d_Hi', strtotime($process->check_period_end ? $process->check_period_end : $process->created)) . '.' . $schedule->report_format; $file_path = dirname(Yii::app()->request->scriptFile) . DIRECTORY_SEPARATOR . "files" . DIRECTORY_SEPARATOR . "schedule_reports" . DIRECTORY_SEPARATOR . $id; $report_string = file_exists($file_path) ? file_get_contents($file_path) : ($report_string = ''); It::downloadFile($report_string, $file_name); }
public static function getInfoForRegenerate($id) { return ScheduleReportProcessed::model()->with('ScheduleReportToStation.schedule_report')->findByPk($id); }
public function actionSetup() { $criteria = new CDbCriteria(); $criteria->condition = "ord > 0"; $criteria->order = "ord ASC"; $meas_types = RefbookMeasurementType::model()->findAll($criteria); if ($meas_types) { foreach ($meas_types as $key => $value) { $sql = "SELECT `t1`.`metric_id`, CONCAT(`t2`.`html_code`, ' (', `t2`.`full_name`, ')') AS `name`, `t1`.`is_main`, `t1`.`measurement_type_metric_id`\n FROM `" . RefbookMeasurementTypeMetric::model()->tableName() . "` `t1`\n LEFT JOIN `" . RefbookMetric::model()->tableName() . "` `t2` ON `t2`.`metric_id` = `t1`.`metric_id`\n WHERE `t1`.`measurement_type_id` = '" . $value->measurement_type_id . "'"; $meas_types[$key]->metrics_list = Yii::app()->db->createCommand($sql)->queryAll(); } } if (Yii::app()->request->isPostRequest && isset($_POST['main_metric'])) { foreach ($_POST['main_metric'] as $key => $value) { if ($meas_types[$key]->metrics_list) { foreach ($meas_types[$key]->metrics_list as $v1) { $update = array('is_main' => $v1['metric_id'] == $value ? 1 : 0); RefbookMeasurementTypeMetric::model()->updateByPk($v1['measurement_type_metric_id'], $update); } } } StationSensorFeature::updateMetric(); $DB = array('db' => CStubActiveRecord::getDbConnect(), 'db_long' => CStubActiveRecord::getDbConnect(true)); foreach ($DB as $db) { $db->createCommand("DELETE FROM `" . ScheduleReportProcessed::model()->tableName() . "`")->query(); $db->createCommand("DELETE FROM `" . ForwardedMessage::model()->tableName() . "`")->query(); $db->createCommand("DELETE FROM `" . StationCalculationData::model()->tableName() . "`")->query(); $db->createCommand("DELETE FROM `" . SeaLevelTrend::model()->tableName() . "`")->query(); $db->createCommand("DELETE FROM `" . SensorDataMinute::model()->tableName() . "`")->query(); $db->createCommand("DELETE FROM `" . SensorData::model()->tableName() . "`")->query(); $db->createCommand("DELETE FROM `" . ListenerLog::model()->tableName() . "`")->query(); } It::memStatus('admin_metrics_saved'); $this->redirect($this->createUrl('admin/setup')); } $this->render('setup', array('meas_types' => $meas_types)); }
public function m_0_4_10() { @apache_setenv('no-gzip', 1); @ini_set('zlib.output_compression', 0); @ini_set('implicit_flush', 1); ini_set('memory_limit', '-1'); $this->flushNotification("\n...Please wait... Updating is going on... DO NOT LEAVE THIS PAGE!"); Yii::app()->db->createCommand("COMMIT")->query(); $this->flushNotification("<br/><br/>...Drop field `description` from `calculation_handler`!"); Yii::app()->db->createCommand("ALTER TABLE `calculation_handler` DROP `description`")->query(); Yii::app()->db->createCommand("COMMIT")->query(); Yii::app()->db->createCommand("ALTER TABLE `schedule_report_processed` DROP `serialized_report_problems`")->query(); Yii::app()->db->createCommand("COMMIT")->query(); $this->flushNotification("<br/><br/>...Move schduled outputs from database into files !"); $sql = "SELECT `schedule_processed_id`, `report_string_initial`\n FROM `" . ScheduleReportProcessed::model()->tableName() . "`"; $res = Yii::app()->db->createCommand($sql)->queryAll(); if ($res) { $files_path = dirname(Yii::app()->request->scriptFile) . DIRECTORY_SEPARATOR . "files" . DIRECTORY_SEPARATOR . "schedule_reports"; if (!is_dir($files_path)) { mkdir($files_path, 0777, TRUE); } foreach ($res as $key => $value) { $file_path = $files_path . DIRECTORY_SEPARATOR . $value['schedule_processed_id']; if ($h = fopen($file_path, "w+")) { fwrite($h, $value['report_string_initial']); fclose($h); } } } Yii::app()->db->createCommand("COMMIT")->query(); $this->flushNotification("<br/><br/>...Delete useless columns !"); Yii::app()->db->createCommand("ALTER TABLE `schedule_report_processed` DROP `report_string_initial`")->query(); Yii::app()->db->createCommand("COMMIT")->query(); Yii::app()->db->createCommand("ALTER TABLE `schedule_report_processed` DROP `report_string_changed`")->query(); Yii::app()->db->createCommand("COMMIT")->query(); It::memStatus('update__success'); $this->flushNotification('<script type="text/javascript"> setTimeout(function(){document.location.href="' . Yii::app()->controller->createUrl('update/index') . '"}, 5000)</script>'); }
/** * Remove all old sensors data from actual database * @param type $timestamp */ private function removeDataBeforeDate($timestamp) { return; //TODO: because of LONG DB $this->addBackupLog("DELETE all records before " . $timestamp); It::debug("DELETE all records before " . $timestamp, 'backup_database'); // delete from `listener` $sql = "SELECT listener_id FROM `" . Listener::model()->tableName() . "` WHERE `created` <= '" . $timestamp . "'"; $res = Yii::app()->db->createCommand($sql)->queryColumn(); It::debug("DELETE " . count($res) . " from " . Listener::model()->tableName(), 'backup_database'); $this->addBackupLog("DELETE " . count($res) . " from " . Listener::model()->tableName()); if ($res) { $sql = "DELETE FROM `" . Listener::model()->tableName() . "` WHERE `created` <= '" . $timestamp . "'"; $res = Yii::app()->db->createCommand($sql)->query(); } // delete from `listener_log` $sql = "SELECT log_id FROM `" . ListenerLog::model()->tableName() . "` WHERE `created` <= '" . $timestamp . "' "; $res = Yii::app()->db->createCommand($sql)->queryColumn(); It::debug("DELETE " . count($res) . " from " . ListenerLog::model()->tableName(), 'backup_database'); $this->addBackupLog("DELETE " . count($res) . " from " . ListenerLog::model()->tableName()); if ($res) { $sql = "DELETE FROM `" . ListenerLog::model()->tableName() . "` WHERE `created` <= '" . $timestamp . "'"; $res = Yii::app()->db->createCommand($sql)->query(); } // delete from `schedule_processed` $sql = "SELECT `schedule_processed_id` FROM `" . ScheduleReportProcessed::model()->tableName() . "` WHERE `created` <= '" . $timestamp . "'"; $res = Yii::app()->db->createCommand($sql)->queryColumn(); It::debug("DELETE " . count($res) . " from " . ScheduleReportProcessed::model()->tableName(), 'backup_database'); $this->addBackupLog("DELETE " . count($res) . " from " . ScheduleReportProcessed::model()->tableName()); if ($res) { $sql = "DELETE FROM `" . ScheduleReportProcessed::model()->tableName() . "` WHERE `created` <= '" . $timestamp . "'"; $res = Yii::app()->db->createCommand($sql)->query(); } // delete from `xml_log` $sql = "SELECT `xml_log_id` FROM `" . XmlLog::model()->tableName() . "` WHERE `created` <= '" . $timestamp . "'"; $res = Yii::app()->db->createCommand($sql)->queryColumn(); It::debug("DELETE " . count($res) . " from " . XmlLog::model()->tableName(), 'backup_database'); $this->addBackupLog("DELETE " . count($res) . " from " . XmlLog::model()->tableName()); if ($res) { $sql = "DELETE FROM `" . XmlLog::model()->tableName() . "` WHERE `created` <= '" . $timestamp . "'"; $res = Yii::app()->db->createCommand($sql)->query(); } }
public function actionScheduleResaveReport() { $return = array('ok' => 0); $schedule_processed_id = isset($_REQUEST['schedule_processed_id']) ? intval($_REQUEST['schedule_processed_id']) : null; if ($schedule_processed_id && isset($_REQUEST['ScheduleReportProcessed']['report_string_initial'])) { $report = ScheduleReportProcessed::model()->long()->findByPk($schedule_processed_id); if ($report) { $file_path = dirname(Yii::app()->request->scriptFile) . DIRECTORY_SEPARATOR . "files" . DIRECTORY_SEPARATOR . "schedule_reports" . DIRECTORY_SEPARATOR . $schedule_processed_id; file_put_contents($file_path, $_REQUEST['ScheduleReportProcessed']['report_string_initial']); if (!$report->getErrors()) { $return['ok'] = 1; } else { $return['errors'] = $report->getErrors(); } } else { $return['errors'][] = 'Unknown report process'; } } print json_encode($return); CApplication::end(); }