public function actionCreate($id) { $forum = Forum::model()->findByPk($id); if (null == $forum) { throw new CHttpException(404, 'Forum not found.'); } if ($forum->is_locked && (Yii::app()->user->isGuest || !Yii::app()->user->isForumAdmin())) { throw new CHttpException(403, 'Forum is locked.'); } $model = new PostForm(); $model->setScenario('create'); // This makes subject required if (isset($_POST['PostForm'])) { if (!isset($_POST['YII_CSRF_TOKEN']) || $_POST['YII_CSRF_TOKEN'] != Yii::app()->getRequest()->getCsrfToken()) { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } $model->attributes = $_POST['PostForm']; if ($model->validate()) { $thread = new Thread(); $thread->forum_id = $forum->id; $thread->subject = $model->subject; $thread->author_id = Yii::app()->user->id; $thread->lastPost_user_id = Yii::app()->user->id; $thread->lastPost_time = time(); $thread->save(false); $post = new Post(); $post->author_id = Yii::app()->user->id; $post->thread_id = $thread->id; $post->content = $model->content; $post->save(false); $this->redirect($thread->url); } } $this->render('newThread', array('forum' => $forum, 'model' => $model)); }
public function testCreate() { $thread = new Thread(); $thread->crashreport_id = 1; $thread->thread_id = 4094; $thread->stack_trace_md5 = '1234567890123456789012'; $saved = $thread->save(); $this->assertTrue($saved); // Find created model $model = Thread::model()->findByAttributes(array('thread_id' => 4094)); $this->assertTrue($model != null); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Thread(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Thread'])) { $model->attributes = $_POST['Thread']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->thread_id)); } } $this->render('create', array('model' => $model)); }
public static function addThread() { $params = $_POST; $time = date('Y-m-d G:i:s'); $attributes = array('name' => $params['name'], 'created' => $time, 'lastpost' => $time, 'user_id' => $_SESSION['user']); $thread = new Thread($attributes); $errors = $thread->errors(); if (count($errors) == 0) { $thread->save(); Redirect::to('/thread/' . $thread->id); } else { View::make('thread/thread_create.html', array('errors' => $errors, 'attributes' => $attributes)); } }
public function executeSendMessage(sfWebRequest $request) { $this->forward404Unless($request->isMethod('POST')); $form = new MessageForm($this->getUser()->getAttribute('id')); $form->bind($request->getParameter('message')); if ($form->isValid()) { $thread = new Thread(); $thread->subject = $request->getPostParameter('message[subject]'); $thread->recipients = json_encode(array($this->getUser()->getAttribute('id'), $request->getPostParameter('message[recipients]'))); $thread->save(); $message = new Message(); $message->message_id = md5(date(DateTime::ISO8601)); $message->thread_id = $thread->thread_id; $message->author_id = $this->getUser()->getAttribute('id'); $message->body = $request->getPostParameter('message[message]'); $message->save(); $this->redirectWithInfo('Your message was successfully sent.', 'messages/index'); } $this->redirectWithInfo('An error occured sending your message. Please try again later.'); }
/** * testSaveEmpty method * * @return void */ public function testSaveEmpty() { $this->loadFixtures('Thread'); $TestModel = new Thread(); $data = array(); $expected = $TestModel->save($data); $this->assertFalse($expected); }
public function createthread($name) { if ($name == 'thong-bao.html') { $forum = 1; } else { if ($name == 'thao-luan-chung.html') { $forum = 2; } else { if ($name == 'dong-gop-y-kien.html') { $forum = 3; } else { if ($name == 'buon-ban.html') { $forum = 4; } else { if ($name == 'kinh-nghiem-choi.html') { $forum = 5; } else { if ($name == 'bang-hoi.html') { $forum = 6; } else { if ($name == 'report-loi-game.html') { $forum = 7; } else { return Redirect::to('/dien-dan.html'); } } } } } } } $title = Input::get('title'); $text = Input::get('text'); $user_id = Session::get('WebUserId'); $thread = new Thread(); $thread->webuser_id = $user_id; $thread->forum = $forum; $thread->title = $title; $thread->reply = 0; $thread->lastuser_id = $user_id; $thread->created_at = time(); $thread->updated_at = time(); $thread->save(); $first_post = new Post(); $first_post->webuser_id = $user_id; $first_post->thread_id = $thread->id; $first_post->text = $text; $first_post->save(); $view = ForumViewCount::find($forum); $view->topic = $view->topic + 1; $view->save(); return Redirect::to("/dien-dan/" . $name); }
/** * Make a new thread */ public function post_new() { $data = Input::get(); $rules = array('board_id' => 'required', 'subject' => 'required', 'body' => 'required'); $val = Validator::make($data, $rules); if ($val->fails()) { return Redirect::to('/')->with_input()->with_errors($val); } else { // make the thread! $user = Auth::user(); $thread = new Thread(); $thread->board_id = $data['board_id']; $thread->user_id = $user->id; $thread->subject = $data['subject']; $thread->postcount = 1; $thread->save(); // make the 1st post $post = new Post(); $post->user_id = $user->id; $post->thread_id = $thread->id; $post->body = $data['body']; $post->save(); // update the users post count $user->posts++; $user->save(); return Redirect::to('thread/view/' . $thread->id); } return Response::json($data); }
/** * Makes a new thread by this user * * @param int $forumID * @param string $threadTitle * @param string $postBody * @return bool */ public function makeNewThread($forumID, $threadTitle, $postBody, $cat_id, $notify_email, $notify_pm, $tags, $school_grade) { //If the user is banned, they can't make a new thread if ($this->getHidden()) { return false; } //Create the thread $thread = new Thread(); $thread->setTitle($threadTitle); $thread->setPosterId($this->getId()); $thread->setForumId($forumID); $thread->setCategoryId($cat_id); $thread->setNotifyEmail($notify_email); $thread->setNotifyPm($notify_pm); // $thread->setNotifySms($notify_sms); // $thread->setCellNumber($cell_number); $thread->setTags($tags); $thread->setSchoolGrade($school_grade); //If the thread wasn't properly added to the DB, return false if (!$thread->save()) { return false; } //Create the first post return $this->makeNewPost($thread->getId(), $postBody); }
public function createthread($name) { $forums = HelperFunctions::forum_list(); foreach ($forums as $key => $f) { if ($f[0] == $name) { $forum = $key + 1; } } if ($forum == 0) { return Redirect::to("/dien-dan.html"); } $title = Input::get('title'); $text = Input::get('text'); $user_id = Session::get('WebUserId'); $thread = new Thread(); $thread->webuser_id = $user_id; $thread->forum = $forum; $thread->title = $title; $thread->reply = 0; $thread->lastuser_id = $user_id; $thread->created_at = time(); $thread->updated_at = time(); $thread->save(); $first_post = new Post(); $first_post->webuser_id = $user_id; $first_post->thread_id = $thread->id; $first_post->text = $text; $first_post->save(); $last_post_seed = new Post(); $last_post_seed->webuser_id = $user_id; $last_post_seed->thread_id = $thread->id; $last_post_seed->text = 'seed_for_textbox'; $last_post_seed->status = 1; $last_post_seed->save(); $view = ForumViewCount::find($forum); $view->topic = $view->topic + 1; $view->save(); return Redirect::to("/dien-dan/" . $name); }
/** * This method reads crash report information from XML file and * updates appropriate database tables. * @param string $xmlFileName XML file name. * @param integer $crashReportId Crash report ID in database. * @return boolean true on success. */ public function importCrashReportFromXml($xmlFileName, $crashReportId) { $status = false; // Find appropriate {{crashreport}} table record $criteria = new CDbCriteria(); $criteria->select = '*'; $criteria->condition = 'id=' . $crashReportId; $crashReport = CrashReport::model()->find($criteria); if ($crashReport == Null) { Yii::log('Not found crash report id=' . $crashReportId); return $status; } $crashReport->status = CrashReport::STATUS_PROCESSED; // Begin DB transaction $transaction = Yii::app()->db->beginTransaction(); try { // Load XML file $doc = @simplexml_load_file($xmlFileName); if ($doc == Null) { throw new Exception('CrashFix service has encountered an error when retrieving information from crash report file'); } // Get command return status message from XML $elemSummary = $doc->Summary; if ($elemSummary == Null) { throw new Exception('Internal error: not found Summary element in XML document ' . $xmlFileName); } // Extract crash report info $generatorVersion = (int) $elemSummary->GeneratorVersion; $crashGuid = (string) $elemSummary->CrashGUID; $appName = (string) $elemSummary->ApplicationName; $appVersion = (string) $elemSummary->ApplicationVersion; $exeImage = (string) $elemSummary->ExecutableImage; $dateCreated = (string) $elemSummary->DateCreatedUTC; $osNameReg = (string) $elemSummary->OSNameReg; $osVersionMinidump = (string) $elemSummary->OSVersionMinidump; $osIs64Bit = (int) $elemSummary->OSIs64Bit; $geoLocation = (string) $elemSummary->GeographicLocation; $productType = (string) $elemSummary->ProductType; $cpuArchitecture = (string) $elemSummary->CPUArchitecture; $cpuCount = (int) $elemSummary->CPUCount; $guiResourceCount = (int) $elemSummary->GUIResourceCount; $openHandleCount = $elemSummary->OpenHandleCount; $memoryUsageKbytes = $elemSummary->MemoryUsageKbytes; $exceptionType = (string) $elemSummary->ExceptionType; $exceptionAddress = $elemSummary->ExceptionAddress; $sehExceptionCode = $elemSummary->SEHExceptionCode; $exceptionThreadID = $elemSummary->ExceptionThreadID; $exceptionModuleName = (string) $elemSummary->ExceptionModuleName; $exceptionModuleBase = (string) $elemSummary->ExceptionModuleBase; if (strlen($exceptionModuleBase) == 0) { $exceptionModuleBase = 0; } $crashReport->exceptionmodulebase = $exceptionModuleBase; $userEmail = (string) $elemSummary->UserEmail; $problemDescription = (string) $elemSummary->ProblemDescription; // Set crash report fields $crashReport->status = CrashReport::STATUS_PROCESSED; $crashReport->crashrptver = $generatorVersion; $crashReport->crashguid = $crashGuid; $ver = AppVersion::createIfNotExists($appVersion, $crashReport->project_id); $crashReport->appversion_id = $ver->id; if (strlen($userEmail) != 0) { $crashReport->emailfrom = $userEmail; } if (strlen($problemDescription) != 0) { $crashReport->description = $problemDescription; } if (strlen($dateCreated) != 0) { $crashReport->date_created = strtotime($dateCreated); } $crashReport->os_name_reg = $osNameReg; $crashReport->os_ver_mdmp = $osVersionMinidump; $crashReport->os_is_64bit = $osIs64Bit; $crashReport->geo_location = $geoLocation; $crashReport->product_type = $productType; $crashReport->cpu_architecture = $cpuArchitecture; $crashReport->cpu_count = $cpuCount; $crashReport->gui_resource_count = $guiResourceCount; $crashReport->memory_usage_kbytes = $memoryUsageKbytes; $crashReport->open_handle_count = $openHandleCount; $crashReport->exception_type = $exceptionType; if (strlen($sehExceptionCode) != 0) { $crashReport->exception_code = $sehExceptionCode; } if (strlen($exceptionThreadID) != 0) { $crashReport->exception_thread_id = $exceptionThreadID; } if (strlen($exceptionAddress) != 0) { $crashReport->exceptionaddress = $exceptionAddress; } if (strlen($exceptionModuleName) != 0) { $crashReport->exceptionmodule = $exceptionModuleName; } if (strlen($exceptionModuleBase) != 0) { $crashReport->exceptionmodulebase = $exceptionModuleBase; } $crashReport->exe_image = $exeImage; // Validate crash report fields if (!$crashReport->validate()) { // There are some errors $errors = $crashReport->getErrors(); foreach ($errors as $fieldName => $fieldErrors) { foreach ($fieldErrors as $errorMsg) { // Add an error message to log Yii::log('Error in crashreport data (' . $crashReport->{$fieldName} . '): ' . $errorMsg, 'error'); // Associate a processing error with crash report record $this->addProcessingError(ProcessingError::TYPE_CRASH_REPORT_ERROR, $crashReport->id, $errorMsg . ' (' . $crashReport->{$fieldName} . ')'); // Clear field - this should fix the error unset($crashReport->{$fieldName}); } } // Clear validation errors $crashReport->clearErrors(); } // Extract file items $elemFileList = $doc->FileList; if ($elemFileList != Null) { $i = 0; foreach ($elemFileList->Row as $elemRow) { $i++; if ($i == 1) { continue; } // Skip header row $itemNo = $elemRow->Cell[0]['val']; $itemName = $elemRow->Cell[1]['val']; $itemDesc = $elemRow->Cell[2]['val']; $fileItem = new FileItem(); $fileItem->filename = $itemName; $fileItem->description = $itemDesc; $fileItem->crashreport_id = $crashReportId; if (!$fileItem->save()) { throw new Exception('Could not save file item record'); } } } // Extract custom props $elemAppDefinedProps = $doc->ApplicationDefinedProperties; if ($elemAppDefinedProps != Null) { $i = 0; foreach ($elemAppDefinedProps->Row as $elemRow) { $i++; if ($i == 1) { continue; } // Skip header row $itemNo = $elemRow->Cell[0]['val']; $name = $elemRow->Cell[1]['val']; $val = $elemRow->Cell[2]['val']; $customProp = new CustomProp(); $customProp->name = $name; $customProp->value = $val; $customProp->crashreport_id = $crashReportId; if (!$customProp->save()) { throw new Exception('Could not save custom property record'); } } } // Extract the list of modules $elemModuleList = $doc->ModuleList; if ($elemModuleList != Null && $elemModuleList->count() != 0) { $i = 0; foreach ($elemModuleList->Row as $elemRow) { $i++; if ($i == 1) { continue; } // Skip header row $itemNo = $elemRow->Cell[0]['val']; $name = $elemRow->Cell[1]['val']; $symLoadStatus = $elemRow->Cell[2]['val']; $loadedPdbName = $elemRow->Cell[3]['val']; $loadedPdbGUID = $elemRow->Cell[4]['val']; $fileVersion = $elemRow->Cell[5]['val']; $timeStamp = $elemRow->Cell[6]['val']; $guidnAge = $elemRow->Cell[7]['val']; $module = new Module(); $module->crashreport_id = $crashReportId; $module->name = $name; $module->sym_load_status = $symLoadStatus; $module->file_version = $fileVersion; $module->timestamp = $timeStamp; $module->matching_pdb_guid = $guidnAge; $debugInfo = DebugInfo::model()->findByAttributes(array('guid' => $loadedPdbGUID)); if ($debugInfo != null) { $module->loaded_debug_info_id = $debugInfo->id; } if (!$module->save()) { throw new Exception('Could not save module record'); } } } // Extract the list of stack traces foreach ($doc->StackTrace as $elemStackTrace) { $threadId = $elemStackTrace->ThreadID; $stackTraceMD5 = $elemStackTrace->StackTraceMD5; $thread = new Thread(); $thread->thread_id = $threadId; $thread->crashreport_id = $crashReportId; if (strlen($stackTraceMD5) != 0) { $thread->stack_trace_md5 = $stackTraceMD5; } if (!$thread->save()) { throw new Exception('Could not save thread record'); } $i = 0; foreach ($elemStackTrace->Row as $elemRow) { $i++; if ($i == 1) { continue; } // Skip header row $title = $elemRow->Cell[0]['val']; $addrPC = $elemRow->Cell[1]['val']; $moduleName = $elemRow->Cell[2]['val']; $offsInModule = $elemRow->Cell[3]['val']; $symName = $elemRow->Cell[4]['val']; $undSymName = $elemRow->Cell[5]['val']; $offsInSym = $elemRow->Cell[6]['val']; $srcFile = $elemRow->Cell[7]['val']; $srcLine = $elemRow->Cell[8]['val']; $offsInLine = $elemRow->Cell[9]['val']; $stackFrame = new StackFrame(); $stackFrame->thread_id = $thread->id; $stackFrame->addr_pc = $addrPC; if (strlen($moduleName) != 0) { $module = Module::model()->findByAttributes(array('name' => $moduleName, 'crashreport_id' => $crashReportId)); if ($module != null) { $stackFrame->module_id = $module->id; } $stackFrame->offs_in_module = $offsInModule; } if (strlen($symName) != 0) { $stackFrame->symbol_name = $symName; } if (strlen($undSymName) != 0) { $stackFrame->und_symbol_name = $undSymName; } if (strlen($offsInSym) != 0) { $stackFrame->offs_in_symbol = $offsInSym; } if (strlen($srcFile) != 0) { $stackFrame->src_file_name = $srcFile; } if (strlen($srcLine) != 0) { $stackFrame->src_line = $srcLine; } if (strlen($offsInLine) != 0) { $stackFrame->offs_in_line = $offsInLine; } if (!$stackFrame->save()) { throw new Exception('Could not save stack frame record'); } } } // Commit transaction $transaction->commit(); // Success. $status = true; } catch (Exception $e) { // Rollback transaction $transaction->rollback(); // Add a message to log Yii::log($e->getMessage(), 'error'); $crashReport->status = CrashReport::STATUS_INVALID; // Associate a processing error with crash report record $this->addProcessingError(ProcessingError::TYPE_CRASH_REPORT_ERROR, $crashReport->id, $e->getMessage()); $status = false; } // Update crash group based on new data $crashGroup = $crashReport->createCrashGroup(); if ($crashGroup == Null) { Yii::log('Error creating crash group', 'error'); $status = false; } $crashReport->groupid = $crashGroup->id; // Update crash report $saved = $crashReport->save(); if (!$saved) { Yii::log('Error saving AR crashReport', 'error'); $status = false; } if (!$saved || !$crashReport->checkQuota()) { Yii::log('Error checking crash report quota', 'error'); $status = false; // Delete crash report $crashReport = $crashReport = CrashReport::model()->find('id=' . $crashReport->id); $crashReport->delete(); } // Return status return $status; }