public function actionOperation() { $post = file_get_contents("php://input"); $postData = CJSON::decode($post, true); $this->_device->ifaces[$postData['iface_id']]->saveAttributes(array('lastactivity' => $postData['start'])); $operation = new Operation(); $postData['alarm'] = $postData['alarm'] ? 1 : 0; $operation->attributes = $postData; $transaction = Yii::app()->db->beginTransaction(); try { $operation->save(); $operation_id = $operation->id; foreach ($postData['records'] as $record) { $record['operation_id'] = $operation_id; $recordModel = new Record(); $recordModel->attributes = $record; $recordModel->save(); } $transaction->commit(); $this->_sendResponse(200); } catch (Exception $e) { $transaction->rollBack(); $this->_sendResponse(400); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Operation(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Operation'])) { $model->attributes = $_POST['Operation']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function actionCreate() { $model = new Operation(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Operation'])) { $model->attributes = $_POST['Operation']; if ($model->save()) { Yii::app()->user->setFlash('success', '儲存成功.'); $this->redirect(array('update', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function save() { try { if ($this->id) { $model = Operation::model()->findByPk($this->id); if (empty($model)) { throw new CDbException('参数出错', 1, []); } } else { $model = new Operation(); } $model->attributes = ['name' => $this->name, 'description' => $this->description, 'module' => $this->module, 'controller' => $this->controller, 'action' => $this->action, 'status' => $this->status, 'sort' => $this->sort]; if ($model->save() === false) { throw new CDbException('更新用户出错', 2, $model->getErrors()); } } catch (CDbException $e) { $this->addErrors($e->errorInfo); return false; } return true; }
public function testDeleteOldOperations() { // Create 10 operations $i = 0; for ($i = 0; $i < 10; $i++) { $op = new Operation(); $op->status = Operation::STATUS_SUCCEEDED; $op->timestamp = time(); $op->srcid = $i; $op->cmdid = '1234.' . $i; $op->optype = Operation::OPTYPE_IMPORTPDB; $op->operand1 = "C:\\Program Files\\Apache Software Foundations\\htdocs\\crashfix\\protected\\data\\debugInfo\\CrashRpt{$i}.pdb"; $op->operand2 = "C:\\Program Files\\Apache Software Foundations\\htdocs\\crashfix\\protected\runtime\tmp1234{$i}.tmp"; $this->assertTrue($op->save()); } // Delete old operations Operation::deleteOldOperations(5); // Expect there are 5 ops now $count = Operation::model()->count(); $this->assertTrue($count == 5); }
/** * @before _secure, _vendor */ public function settings() { $this->seo(array("title" => "Settings", "view" => $this->getLayoutView())); $view = $this->getActionView(); $centre = Centre::first(array("id = ?" => $this->member->centre_id)); $location = Location::first(array("id = ?" => $centre->location_id)); $area = Area::first(array("id = ?" => $location->area_id)); if (RequestMethods::post("action") == "settings") { $phone = RequestMethods::post("phone"); $user = $this->user; $message = null; if ($phone != $user->phone) { $exist = User::first(array("phone = ?" => $phone)); if ($exist) { $message = "Phone number already exists"; } else { $user->phone = $phone; } } $user->name = RequestMethods::post("name"); $user->save(); $this->setUser($user); $location = \Location::saveRecord($user, $location); $phone = RequestMethods::post("cphone"); if ($centre->phone != $phone) { $exist = Centre::first(array("phone = ?" => $phone)); if ($exist) { $message = "Landline already exists!!"; } else { $centre->phone = $phone; $centre->save(); } } if (!$message) { $message = "Info updated!!"; } $view->set("message", $message); } if (RequestMethods::post("action") == "operations") { $operations = RequestMethods::post("operations"); foreach ($operations as $key => $value) { $operation = Operation::first(array("centre_id = ?" => $id, "area_id = ?" => $value)); if (!$operation) { $operation = new Operation(array("user_id" => $this->user->id, "centre_id" => $id, "organization_id" => $this->organization->id, "area_id" => $value, "live" => 1)); $operation->save(); } } } $ops = Operation::all(array("centre_id = ?" => $id), array("area_id")); $opa = array(); foreach ($ops as $o) { $opa[] = $o->area_id; } $view->set("centre", $centre); $view->set("area", $area); $view->set("location", $location); $view->set("opa", $opa); }
public function do_batch_ledcoin_addition() { $this->load->helper('operations'); $this->db->trans_begin(); build_validator_from_form($this->get_batch_ledcoin_addition_form()); if ($this->form_validation->run()) { $batch_amount_data = $this->input->post('batch_amount'); $person_amount_data = $this->input->post('person_amount'); $workplace = new Workplace(); if ((int) $batch_amount_data['workplace_id'] > 0) { $workplace->get_by_id((int) $batch_amount_data['workplace_id']); if (!$workplace->exists()) { $this->db->trans_rollback(); add_error_flash_message('Zamestnanie sa nenašlo.'); redirect(site_url('operations/batch_ledcoin_addition')); } } $persons = new Person(); $persons->where('admin', 0); $persons->get_iterated(); $total_added = 0; foreach ($persons as $person) { if (array_key_exists($person->id, $person_amount_data) && (double) $person_amount_data[$person->id] > 0) { $total_added += (double) $person_amount_data[$person->id]; } } $remaining = 0; if ($total_added > 0 && $batch_amount_data['addition_type'] == Operation::ADDITION_TYPE_TRANSFER && !operations_ledcoin_addition_possible($total_added, $remaining)) { $this->db->trans_rollback(); add_error_flash_message('Nedá sa prideliť <strong>' . $total_added . '</strong> ' . get_inflection_ledcoin($total_added) . ', na účte vedúcich zostáva iba <strong>' . $remaining . '</strong> ' . get_inflection_ledcoin($remaining) . '.'); redirect('operations'); return; } $persons = new Person(); $persons->where('admin', 0); $persons->get_iterated(); $successful_count = 0; $error_count = 0; $successful_messages = array(); $error_messages = array(); $total_added = 0; foreach ($persons as $person) { if (array_key_exists($person->id, $person_amount_data) && (double) $person_amount_data[$person->id] > 0) { $operation = new Operation(); $operation->admin_id = auth_get_id(); $operation->amount = (double) $person_amount_data[$person->id]; $operation->type = Operation::TYPE_ADDITION; $operation->subtraction_type = Operation::SUBTRACTION_TYPE_DIRECT; $operation->addition_type = $batch_amount_data['addition_type']; $operation->comment = @$batch_amount_data['comment']; if ($operation->save(array('person' => $person, 'workplace' => $workplace))) { $total_added += (double) $operation->amount; $successful_messages[] = 'Účastník <strong>' . $person->name . ' ' . $person->surname . '</strong> dostal <strong>' . (double) $operation->amount . '</strong> ' . get_inflection_ledcoin((double) $operation->amount) . '.'; $successful_count++; } else { $error_count++; $error_messages[] = 'Účastníkovi <strong>' . $person->name . ' ' . $person->surname . '</strong> sa nepodarilo prideliť LEDCOIN.'; } } } if ($total_added > 0 && $batch_amount_data['addition_type'] == Operation::ADDITION_TYPE_TRANSFER && !operations_ledcoin_limit_check($total_added)) { add_common_flash_message('Pozor, celkovým pridaním ' . $total_added . ' LEDCOIN-ov bol prekročený denný limit. Pred pridaním už bolo pridaných ' . operations_ledcoin_added_in_day() . ' z ' . operations_ledcoin_daily_limit() . ' LEDCOIN-ov!'); } if ($successful_count == 0 && $error_count == 0) { $this->db->trans_rollback(); add_error_flash_message('Nikomu nebol pridelený LEDCOIN, nakoľko bol odoslaný prázdny formulár.'); redirect(site_url('operations')); } elseif ($successful_count == 0 && $error_count > 0) { $this->db->trans_rollback(); add_error_flash_message('Nepodarilo sa nikomu pridať LEDCOIN:<br /><br />' . implode('<br />', $error_messages)); } else { $this->db->trans_commit(); if ($successful_count > 0) { add_success_flash_message('LEDCOIN bol pridelený <strong>' . $successful_count . '</strong> ' . get_inflection_by_numbers($successful_count, 'účastníkom', 'účastníkovi', 'účastníkom', 'účastníkom', 'účastníkom', 'účastníkom') . ':<br /><br />' . implode('<br />', $successful_messages)); } if ($error_count > 0) { add_error_flash_message('LEDCOIN sa nepodarilo udeliť <strong>' . $error_count . '</strong> ' . get_inflection_by_numbers($error_count, 'účastníkom', 'účastníkovi', 'účastníkom', 'účastníkom', 'účastníkom', 'účastníkom') . ':<br /><br />' . implode('<br />', $error_messages)); } redirect(site_url('operations')); } } else { $this->db->trans_rollback(); $this->batch_ledcoin_addition(); } }
/** * 匯入術式 */ public function actionOperations() { $this->currentActive = '術式'; $excel = new ExcelUploadForm(); $rows = array(); $errors = array(); if (isset($_POST['ExcelUploadForm'])) { $excel->attributes = $_POST['ExcelUploadForm']; $excel->file = CUploadedFile::getInstance($excel, 'file'); $transaction = Yii::app()->db->beginTransaction(); try { if ($excel->validate()) { $rows = $excel->getContents(); foreach ($rows as $i => $row) { if ($i != ExcelUploadForm::HEADER) { $operation = new Operation(); $operation->name = $row[1]; if (!$operation->save()) { $errorData = array('第' . ($i + 1) . '筆,' . $row[2] => $operation->getErrors()); $errors[] = $errorData; } } } $transaction->commit(); } else { $errors[] = array('Excel' => $excel->getErrors()); } } catch (Exception $e) { $transaction->rollBack(); $errors = $e->getMessage(); } $this->_setFlashMessage($errors); $this->redirect($this->createUrl("/excel/import/{$this->action->id}")); } $this->render('upload', array('excel' => $excel)); }
/** * @before _secure, _vendor */ public function update($id) { $this->seo(array("title" => "Edit Lab", "view" => $this->getLayoutView())); $view = $this->getActionView(); $centre = Centre::first(array("id = ?" => $id)); if (RequestMethods::get("live")) { $centre->live = RequestMethods::get("live", 0); $centre->save(); $this->redirect("/lab/manage"); } $location = Location::first(array("id = ?" => $centre->location_id)); $areas = Area::all(array("city_id = ?" => $location->city_id), array("name", "id")); $manager = User::first(array("id = ?" => $this->member->user_id)); if (RequestMethods::post("action") == "medicallab") { $message = null; $location->street = RequestMethods::post("street"); $location->area_id = RequestMethods::post("area_id"); $location->city_id = RequestMethods::post("city_id"); if ($location->validate()) { $location->save(); } else { $message = "Center location was not saved!!"; } $phone = RequestMethods::post("phone"); if ($phone != $centre->phone) { $exist = Center::first(array("phone = ?" => $phone)); if ($exist) { $message = "Phone number already exists"; } else { $centre->phone = $phone; $centre->save(); } } if (!$message) { $message = "Lab info updated!!"; } $view->set("message", $message); } if (RequestMethods::post("action") == "operations") { $operations = RequestMethods::post("operations"); foreach ($operations as $key => $value) { $operation = Operation::first(array("centre_id = ?" => $id, "area_id = ?" => $value)); if (!$operation) { $operation = new Operation(array("user_id" => $this->user->id, "centre_id" => $id, "organization_id" => $this->organization->id, "area_id" => $value, "live" => 1)); $operation->save(); } } } $ops = Operation::all(array("centre_id = ?" => $id), array("area_id")); $opa = array(); foreach ($ops as $o) { $opa[] = $o->area_id; } $view->set("centre", $centre); $view->set("manager", $manager); $view->set("location", $location); $view->set("areas", $areas); $view->set("opa", $opa); }
/** * makes a new reservation (admin/sales user) */ function addforuser($room_id, $schedule_id, $date) { $room = $this->Reservation->Room->read(null, $room_id); if (!empty($this->data)) { // checks if the user has enough credit to reserve the room $this->data['Reservation']['amount'] = $room['Room']['cost']; if ($this->Session->read('Auth.User.type') != 'web') { $operation['Operation']['user_id'] = $this->data['Reservation']['user_id']; } else { $operation['Operation']['user_id'] = $this->Session->read('Auth.User.id'); } $user = new User(); $userdata = $user->read(null, $operation['Operation']['user_id']); if ($room['Room']['cost'] > $user->getBalance(null, null, false, true)) { $this->Session->setFlash(__('Not enough credit to make the reservation.', true)); $this->set('userdata', $userdata); } else { // registers a new operation of debit type $new_operation = new Operation(); $new_operation->create(); $operation['Operation']['date'] = date('Y-m-d H:i:s'); // date of the operation $operation['Operation']['type'] = 'C'; $operation['Operation']['amount'] = $this->data['Reservation']['amount']; $operation['Operation']['description'] = 'Room Reservation'; // registers the new reservation $reservation['Reservation']['schedule_id'] = $schedule_id; $reservation['Reservation']['room_id'] = $room_id; $reservation['Reservation']['date'] = $date; $reservation['Reservation']['notes'] = $this->data['Reservation']['description']; // NOTE the date of the reservation may be different of the date of the operation //$operation['Operation']['Reservation'][0] = $reservation['Reservation']; if ($new_operation->save($operation)) { $this->Reservation->create(); $reservation['Reservation']['operation_id'] = $new_operation->id; $this->Reservation->save($reservation); $this->Session->setFlash(__('The Reservation has been saved', true)); $this->redirect('/'); } else { //$this->Session->setFlash(__('The Reservation could not be saved. Please try again.', true)); $this->Session->setFlash(__('Please input a description.', true)); } } } $this->set('room', $room); $this->set('schedule', $this->Reservation->Schedule->read(null, $schedule_id)); $this->set('date', $date); $this->set('users', $this->Reservation->Operation->User->find('all', array('conditions' => array('type' => 'web')))); }
private function deletePendingDebugInfoFiles() { // Add a message to log Yii::log("Checking for debug info records marked for deletion...", "info"); // Get debug info files that have status 'Pending Delete' $criteria = new CDbCriteria(); $criteria->select = '*'; $criteria->condition = 'status=' . DebugInfo::STATUS_PENDING_DELETE; $criteria->limit = 20; $debugInfoFiles = DebugInfo::model()->findAll($criteria); if ($debugInfoFiles == Null) { Yii::log('There are no debug info files waiting for deletion', 'info'); } else { Yii::log('Found ' . count($debugInfoFiles) . ' debug info file(s) ready for deletion', 'info'); } foreach ($debugInfoFiles as $debugInfo) { // Determine path to debug info file $fileName = $debugInfo->getLocalFilePath(); // Format daemon command $command = 'assync dumper --delete-debug-info "' . $fileName . '"'; // Execute the command $responce = ""; $retCode = Yii::app()->daemon->execCommand($command, $responce); if ($retCode != 0) { Yii::log('Error executing command ' . $command . ', response = ' . $responce, 'error'); continue; } // Check responce and get command ID from server responce $matches = array(); $check = preg_match('#Assync command \\{([0-9]{1,6}.[0-9]{1,9})\\} has been added to the request queue.#', $responce, $matches); if (!$check || !isset($matches[1])) { Yii::log('Unexpected response from command ' . $command . ', responce = ' . $responce, 'error'); continue; } // Begin DB transaction $transaction = Yii::app()->db->beginTransaction(); try { // Create a new operation record in {{operation}} table. $op = new Operation(); $op->status = Operation::STATUS_STARTED; $op->timestamp = time(); $op->srcid = $debugInfo->id; $op->cmdid = $matches[1]; $op->optype = Operation::OPTYPE_DELETE_DEBUG_INFO; $op->operand1 = $fileName; if (!$op->save()) { throw new Exception('Could not save an operation record'); } // Update existing debug info record in {{debuginfo}} table. $debugInfo->status = DebugInfo::STATUS_DELETE_IN_PROGRESS; if (!$debugInfo->save()) { //$errors = $crashReport->getErrors(); //print_r($errors); throw new Exception('Could not save a debug info record '); } // Commit transaction $transaction->commit(); } catch (Exception $e) { // Roll back transaction $transaction->rollBack(); // Add an error message to log Yii::log('An exception caught: ' . $e->getMessage(), "error"); } } Yii::log("Finished checking for debug info files ready for deletion.", "info"); }