/** * Runs the cron. * * Triggers {@link \Mibew\EventDispatcher\Events::CRON_RUN} event. * * @param Request $request Incoming request. * @return string Rendered page content. */ public function runAction(Request $request) { $cron_key = $request->query->get('cron_key', ''); // Check cron security key if ($cron_key != Settings::get('cron_key')) { // Return an empty response return ''; } // Determine use or not quiet mode $quiet = $request->query->has('q'); set_time_limit(0); // Remove stale cached items $this->getCache()->purge(); // Run cron jobs of the core calculate_thread_statistics(); calculate_operator_statistics(); calculate_page_statistics(); // Trigger cron event $dispatcher = EventDispatcher::getInstance(); $dispatcher->triggerEvent(Events::CRON_RUN); // Update time of last cron run Settings::set('_last_cron_run', time()); if (!$quiet) { // TODO: May be localize it return 'All cron jobs done.'; } }
/** * Performs all periodical actions. * * @return boolean True if all periodical actions are done and false * otherwise. */ public function run() { try { set_time_limit(0); // Update time of last cron run Settings::set('_last_cron_run', time()); // Remove stale cached items $this->cache->purge(); // Run cron jobs of the core calculate_thread_statistics(); calculate_operator_statistics(); calculate_page_statistics(); // Trigger cron event $dispatcher = EventDispatcher::getInstance(); $dispatcher->triggerEvent(Events::CRON_RUN); if (Settings::get('autocheckupdates') == '1') { // Run the update checker $update_checker = $this->getUpdateChecker(); if (!$update_checker->run()) { $this->errors = array_merge($this->errors, $update_checker->getErrors()); return false; } } } catch (\Exception $e) { $this->log[] = $e->getMessage(); return false; } return true; }
/** * Processes submitting of the form which is generated in * {@link \Mibew\Controller\Settings\FeaturesController::showFormAction()} * method. * * @param Request $request Incoming request. * @return string Rendered page content. */ public function submitFormAction(Request $request) { csrf_check_token($request); // Update options in the database. $options = $this->getOptionsList(); foreach ($options as $opt) { $value = $request->request->get($opt) == 'on' ? '1' : '0'; Settings::set($opt, $value); } // Redirect the current operator to the same page using GET method. $redirect_to = $this->generateUrl('settings_features', array('stored' => true)); return $this->redirect($redirect_to); }
/** * Performs all periodical actions. * * @return boolean True if all periodical actions are done and false * otherwise. */ public function run() { try { set_time_limit(0); // Remove stale cached items $this->cache->purge(); // Run cron jobs of the core calculate_thread_statistics(); calculate_operator_statistics(); calculate_page_statistics(); // Trigger cron event $dispatcher = EventDispatcher::getInstance(); $dispatcher->triggerEvent(Events::CRON_RUN); // Update time of last cron run Settings::set('_last_cron_run', time()); } catch (\Exception $e) { $this->log[] = $e->getMessage(); return false; } return true; }
/** * Sets style which is used in the system by default * * @param string $style_name Name of a style */ public static function setDefaultStyle($style_name) { Settings::set('invitation_style', $style_name); }
/** * Processes submitting of the form which is generated in * {@link \Mibew\Controller\Settings\CommonController::showFormAction()} * method. * * @param Request $request Incoming request. * @return string Rendered page content. * @throws BadRequestException If one or more parameters of the request have * wrong format. */ public function submitFormAction(Request $request) { csrf_check_token($request); $errors = array(); $params = array(); $params['email'] = $request->request->get('email'); $params['title'] = $request->request->get('title'); $params['logo'] = $request->request->get('logo'); $params['hosturl'] = $request->request->get('hosturl'); $params['usernamepattern'] = $request->request->get('usernamepattern'); $params['chattitle'] = $request->request->get('chattitle'); $params['geolink'] = $request->request->get('geolink'); $params['geolinkparams'] = $request->request->get('geolinkparams'); $params['cron_key'] = $request->request->get('cronkey'); $send_key = $request->request->get('sendmessagekey'); if (!preg_match("/^c?enter\$/", $send_key)) { throw new BadRequestException('Wrong format of "sendmessagekey" field.'); } $params['sendmessagekey'] = $send_key; $params['left_messages_locale'] = $request->request->get('leftmessageslocale'); if (!in_array($params['left_messages_locale'], get_available_locales())) { $params['left_messages_locale'] = get_home_locale(); } if ($params['email'] && !MailUtils::isValidAddress($params['email'])) { $errors[] = getlocal('Enter a valid email address'); } if ($params['geolinkparams']) { foreach (explode(',', $params['geolinkparams']) as $one_param) { $wrong_param = !preg_match("/^\\s*(toolbar|scrollbars|location|status|menubar|width|height|resizable)=\\d{1,4}\$/", $one_param); if ($wrong_param) { $errors[] = "Wrong link parameter: \"{$one_param}\", " . "should be one of 'toolbar, scrollbars, location, " . "status, menubar, width, height or resizable'"; } } } if (preg_match("/^[0-9A-Za-z]*\$/", $params['cron_key']) == 0) { $errors[] = getlocal('Use only Latin letters(upper and lower case) and numbers in cron key.'); } // Load styles configs $chat_style = $request->request->get('chat_style', ChatStyle::getDefaultStyle()); $chat_style_list = ChatStyle::getAvailableStyles(); if (!in_array($chat_style, $chat_style_list)) { $chat_style = $chat_style_list[0]; } $page_style = $request->request->get('page_style', PageStyle::getDefaultStyle()); $page_style_list = PageStyle::getAvailableStyles(); if (!in_array($page_style, $page_style_list)) { $page_style = $page_style_list[0]; } if (Settings::get('enabletracking')) { $invitation_style = $request->request->get('invitation_style', InvitationStyle::getDefaultStyle()); $invitation_style_list = InvitationStyle::getAvailableStyles(); if (!in_array($invitation_style, $invitation_style_list)) { $invitation_style = $invitation_style_list[0]; } } if (count($errors) != 0) { $request->attributes->set('errors', $errors); // The form should be rebuild. Invoke appropriate action. return $this->showFormAction($request); } // Update system settings foreach ($params as $key => $value) { Settings::set($key, $value); } // Update styles params ChatStyle::setDefaultStyle($chat_style); PageStyle::setDefaultStyle($page_style); if (Settings::get('enabletracking')) { InvitationStyle::setDefaultStyle($invitation_style); } // Redirect the user to the same page using GET method $redirect_to = $this->generateUrl('settings_common', array('stored' => true)); return $this->redirect($redirect_to); }
/** * Releases the lock */ public function release() { Settings::set($this->getInternalName(), '0'); }
/** * Processes submitting of the form which is generated in * {@link \Mibew\Controller\Settings\PerformanceController::showFormAction()} * method. * * @param Request $request Incoming request. * @return string Rendered page content. */ public function submitFormAction(Request $request) { csrf_check_token($request); $errors = array(); $params = array(); $params['online_timeout'] = $request->request->get('onlinetimeout'); if (!is_numeric($params['online_timeout'])) { $errors[] = wrong_field("Operator online time threshold"); } $params['connection_timeout'] = $request->request->get('connectiontimeout'); if (!is_numeric($params['connection_timeout'])) { $errors[] = wrong_field("Connection timeout for messaging window"); } $params['updatefrequency_operator'] = $request->request->get('frequencyoperator'); if (!is_numeric($params['updatefrequency_operator'])) { $errors[] = wrong_field("Operator's console refresh time"); } $params['updatefrequency_chat'] = $request->request->get('frequencychat'); if (!is_numeric($params['updatefrequency_chat'])) { $errors[] = wrong_field("Chat refresh time"); } $params['max_connections_from_one_host'] = $request->request->get('onehostconnections'); if (!is_numeric($params['max_connections_from_one_host'])) { $errors[] = getlocal("\"Max number of threads\" field should be a number"); } $params['thread_lifetime'] = $request->request->get('threadlifetime'); if (!is_numeric($params['thread_lifetime'])) { $errors[] = getlocal("\"Thread lifetime\" field should be a number"); } if (Settings::get('enabletracking')) { $params['updatefrequency_tracking'] = $request->request->get('frequencytracking'); if (!is_numeric($params['updatefrequency_tracking'])) { $errors[] = wrong_field("Tracking refresh time"); } $params['visitors_limit'] = $request->request->get('visitorslimit'); if (!is_numeric($params['visitors_limit'])) { $errors[] = wrong_field("Limit for tracked visitors list"); } $params['invitation_lifetime'] = $request->request->get('invitationlifetime'); if (!is_numeric($params['invitation_lifetime'])) { $errors[] = wrong_field("Invitation lifetime"); } $params['tracking_lifetime'] = $request->request->get('trackinglifetime'); if (!is_numeric($params['tracking_lifetime'])) { $errors[] = wrong_field("Track lifetime"); } } $params['max_uploaded_file_size'] = $request->request->get('maxuploadedfilesize'); if (!is_numeric($params['max_uploaded_file_size'])) { $errors[] = wrong_field("Maximum size of uploaded files"); } if (count($errors) != 0) { $request->attributes->set('errors', $errors); // The form should be rebuild. Invoke appropriate action. return $this->showFormAction($request); } // Update settings in the database foreach ($params as $key => $value) { Settings::set($key, $value); } // Redirect the current operator to the same page using get method. $redirect_to = $this->generateUrl('settings_performance', array('stored' => true)); return $this->redirect($redirect_to); }