/** * 消息存储 */ public function saveMessageAction() { echo date('Y-m-d H:i:s') . ' userMessage is started!' . PHP_EOL; $queueKey = Yaf\Application::app()->getConfig()->redisKeys->messageQueue; $redis = RedisFactory::instance('ims', true); while (true) { $total = 0; while ($message = $redis->lPop($queueKey)) { $messageModel = new MessageModel(); if (!$messageModel->save($message)) { if ($messageModel->getErrCode() == 2002) { //数据库连接消失,消息重新入队,中断进程 $redis->lpush($queueKey, $message); exit; } } pushModel::newMessage($message); $total++; } try { // 闲置时检查Redis连接 $redis->ping(); } catch (\Exception $e) { $redis = RedisFactory::instance('ims', true, true); //重连 } if ($total > 0) { echo date('Y-m-d H:i:s') . ' storage message ' . $total . PHP_EOL; } sleep(1); } exit; }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); $messageModels = LanguageModel::model()->getAllLanguageModels($id); if (isset($_POST['SourceMessageModel'])) { $model->attributes = $_POST['SourceMessageModel']; if ($_POST['MessageModel']) { foreach ($_POST['MessageModel'] as $key => $value) { if (!empty($value['translation'])) { $messageModel = MessageModel::model()->findByAttributes(array('id' => $model->id, 'language' => $key)); if ($messageModel == null) { $messageModel = new MessageModel; $messageModel->language = $key; $messageModel->id = $model->id; $messageModel->setIsNewRecord(true); } else { $messageModel->setIsNewRecord(false); } // die($messageModel->isNewRecord); $messageModel->attributes = $value; $messageModel->save(false); } } } if ($model->save()) $this->redirect(array('index')); } $this->render('update', array( 'model' => $model, 'messageModels' => $messageModels, )); }
/** * 发送消息 * @return boolean */ public function sendAction() { $messageModel = new MessageModel($this->userInfo['userId']); $result = $messageModel->save($this->requestParams); if ($messageModel->getErrCode()) { $this->putError($messageModel->getErrCode(), $messageModel->getErrInfo()); return false; } $this->response($result); return false; }
public function saveAction() { $message = array(); $message['catId'] = 1; $message['sender'] = 10; $message['senderNickname'] = 'sender_10'; $message['receiver'] = 12; $message['receiverNickname'] = 'receiver_12'; $message['content'] = 'content_' . date('YmdHis'); $messageModel = new MessageModel(); $respones = array(); $respones['result'] = $messageModel->save($message); $respones['errCode'] = $messageModel->getErrCode(); $respones['errInfo'] = $messageModel->getErrInfo(); $this->getResponse()->setBody(json_encode($respones)); }
public function sendAction() { $params = $this->getRequest()->getParams(); $toKen = $params['toKen']; $userModel = new UserModel(); $userInfo = $userModel->getUserInfoByToken($toKen); $message = array(); $message['catId'] = 1; $message['sender'] = $userInfo['userId']; $message['senderNickname'] = $userInfo['nickname']; $message['receiver'] = 12; $message['receiverNickname'] = 'receiver_12'; $message['content'] = 'content_' . date('YmdHis'); $messageModel = new MessageModel(); $respones = array(); $respones['result'] = $messageModel->save($message); $respones['errCode'] = $messageModel->getErrCode(); $respones['errInfo'] = $messageModel->getErrInfo(); $this->getResponse()->setBody(json_encode($respones)); }
public function sendAction() { $request = $this->get('request'); $validators = $this->get('model_validation'); // Get the input $from = $this->get('user')->getId(); $to = $request->postVar('to'); $body = $request->postVar('body'); $talkId = 0; // Validate the input $errors = $validators->validateMessage(array('from' => $from, 'to' => $to, 'body' => $body)); if (count($errors) === 0) { // Get the users data (to_user_info is initially set to broadcast info) $fromUser = UserModel::repo()->find($from); $toUser = UserModel::repo()->find($to); if (empty($fromUser) || empty($toUser)) { return $this->json(array('success' => false)); } // Create the message $msg = new MessageModel(array('from_id' => $from, 'to_id' => $to, 'body' => $body, 'talk_id' => $talkId, 'from_user_info' => $fromUser->getData(), 'to_user_info' => $toUser->getData())); $msg->save(); // Return a successful response return $this->json(array('success' => true, 'to' => $to, 'message' => $msg)); } // Return an error response return $this->json(array('success' => false, 'errors' => $errors)); }
/** * Settings screen for role and restriction choice. * * @param object $sender SettingsController. * @return void. * @package ReadOnly * @since 0.1 */ public function settingsController_readOnly_create($sender) { // Define general settings properties. $sender->permission('Garden.Settings.Manage'); $sender->addSideMenu('/dashboard/settings/plugins'); $sender->setData('Title', t('ReadOnly Settings')); $sender->setData('Description', t('ReadOnly Settings Description', 'Choose which roles and actions should be restricted.<br/>You should inform your users about the read only state by ' . anchor('adding a message', '/dashboard/message/add') . ' to the forum.')); // Consolidate/prepare permissions. $permissionModel = Gdn::PermissionModel(); $perms = $permissionModel->PermissionColumns(); unset($perms['PermissionID']); $permissions = array(); foreach ($perms as $key => $value) { $action = substr($key, strrpos($key, '.') + 1); $permissions[$action] .= $key . ', '; } $permissionItems = array(); foreach ($permissions as $key => $value) { $text = $key . '<span>' . trim($value, ', ') . '</span>'; $permissionItems[$text] = $key; } // Consolidate/prepare roles. $roleModel = new RoleModel(); $roles = $roleModel->roles(); $roleItems = array(); foreach ($roles as $role) { $roleItems[$role['Name']] = $role['RoleID']; } // Build form info. $configurationModule = new configurationModule($sender); $configurationModule->initialize(array('ReadOnly.Restrictions' => array('Control' => 'CheckBoxList', 'Description' => t('ReadOnly Settings Restrictions', 'Choose the actions that should be restricted. Below each action is a list of all the current permissions with that action."Add" and "Edit" is recommended.'), 'Items' => $permissionItems, 'LabelCode' => 'Restrictions'), 'ReadOnly.Roles' => array('Control' => 'CheckBoxList', 'Description' => t('Choose the roles that should <strong>not</strong> be restricted (Admin users will always have all permissions).'), 'Items' => $roleItems, 'LabelCode' => 'Roles'), 'ReadOnly.Message' => array('Control' => 'TextBox', 'LabelCode' => 'Message Text', 'Description' => 'It is a good idea to ' . anchor('inform your users', '/dashboard/message') . ' about the restrictions so that they now what\'s going on...', 'Options' => array('MultiLine' => true)), 'ReadOnly.ShowAlert' => array('Control' => 'Checkbox', 'Description' => 'You can choose show or deactivate the message, however.', 'LabelCode' => 'Show Message'))); // Handle alert message. if ($sender->Request->isPostBack()) { $post = $sender->Request->getRequestArguments('post'); $messageModel = new MessageModel(); $messageID = c('ReadOnly.MessageID'); $message = $messageModel->getID($messageID); if (!$post['ReadOnly-dot-Message']) { // Delete message when no text is given. if ($message) { $messageModel->delete(array('MessageID' => $messageID)); removeFromConfig('ReadOnly.MessageID'); } } else { // Check if message already exists. if ($message) { // Set MessageID so that existing message gets updated $formPostValues['MessageID'] = $messageID; } $formPostValues['Location'] = '[Base]'; $formPostValues['AssetTarget'] = 'Content'; $formPostValues['Content'] = $post['ReadOnly-dot-Message']; $formPostValues['CssClass'] = 'AlertMessage'; $formPostValues['Enabled'] = $post['ReadOnly-dot-ShowAlert']; $formPostValues['AllowDismiss'] = false; $formPostValues['TransientKey'] = Gdn::session()->transientKey(); saveToConfig('ReadOnly.MessageID', $messageModel->save($formPostValues)); } } // Show form. $configurationModule->renderAll(); }