/** * @see sfTask */ protected function executeTask($env, $arguments = array(), $options = array()) { /** * Getting the directory where the emails are stored */ $newEmailsDir = sfConfig::get('app_emailToInbox_incomingEmailsDirectory'); // this is very useful for testing if ($arguments['testNewEmailsDirectory']) { $newEmailsDir = $arguments['testNewEmailsDirectory']; } // to make sure staging will not interfere with production $newEmailsDir .= $env == 'prod' ? '' : '-' . $env; $newEmailsPath = glob($newEmailsDir . '/*'); if (!is_dir($newEmailsDir)) { $errorMessage = "{$newEmailsDir} does not exist."; sfErrorNotifier::alert($errorMessage); throw new Exception($errorMessage); } $this->log(''); $this->log(count($newEmailsPath) . " emails to parse in " . $newEmailsDir); $this->log(''); /** * Going through all the emails */ foreach ($newEmailsPath as $newEmailPath) { // we parse the email in a new process so that // if a fatal error stops the parsing of an email, // the others get parsed anyway $cmd = sfConfig::get('sf_root_dir') . "/symfony cron:parse-email {$newEmailPath} --env={$env}"; passthru($cmd); } }
/** * * @param string $query * @return array of integers - taskIds */ public static function searchTasks($query) { $fieldWeights = array('description' => 10, 'note' => 6); $indexName = 'plancake_tasks'; $client = new SphinxClient(); // $client->SetServer (sfConfig::get('app_sphinx_host'), sfConfig::get('app_sphinx_port')); $client->SetFilter("author_id", array(PcUserPeer::getLoggedInUser()->getId())); $client->SetConnectTimeout(1); $client->SetMatchMode(SPH_MATCH_ANY); $client->SetSortMode(SPH_SORT_RELEVANCE); $client->SetRankingMode(SPH_RANK_PROXIMITY_BM25); $client->SetArrayResult(true); $client->SetFieldWeights($fieldWeights); $client->setLimits(0, 100); $results = $client->query($client->EscapeString($query), $indexName); if ($results === false) { $error = "Sphinx Error - " . $client->GetLastError(); sfErrorNotifier::alert($error); } $ids = array(); if (isset($results['matches']) && count($results['matches'])) { foreach ($results['matches'] as $match) { $ids[] = $match['id']; } } return PcTaskPeer::retrieveByPKs($ids); }
/** * @return PcQuoteOfTheDay|null|false */ public static function getUserTodayQuote() { $loggedInUser = PcUserPeer::getLoggedInUser(); $hideableHintsSetting = $loggedInUser->getHideableHintsSetting(); if ($hideableHintsSetting[PcHideableHintsSettingPeer::QUOTE_HINT] === 1) { return false; } $localTimestamp = $loggedInUser->getTime(); $today = date('Ymd', $localTimestamp); $c = new Criteria(); $c->add(self::SHOWN_ON, $today); $todayQuote = self::doSelectOne($c); if (!$todayQuote) { $c = new Criteria(); $c->add(self::SHOWN_ON, null, Criteria::ISNULL); $c->addAscendingOrderByColumn('rand()'); $c->setLimit(1); $todayQuote = self::doSelectOne($c); if ($todayQuote) { $todayQuote->setShownOn($today)->save(); } else { sfErrorNotifier::alert("There are no quotes available anymore."); } } return $todayQuote; }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $env = $options['env']; $availableEnvironments = array('dev', 'staging', 'prod'); if (!in_array($env, $availableEnvironments)) { throw new InvalidArgumentException("{$env} is not an environment."); } require_once dirname(__FILE__) . '/../../../config/ProjectConfiguration.class.php'; $configuration = ProjectConfiguration::getApplicationConfiguration('auto', $env, true); sfContext::createInstance($configuration); try { $this->executeTask($env, $arguments, $options); } catch (Exception $e) { sfErrorNotifier::alert($e->getMessage() . ' - ' . print_r($e->getTrace(), true)); } }
/** * This is tested with Google Calendar * * N.B.: This assumes that we are provided also with a DTSTART parameter * * It doesn't handle the UNTIL and COUNT parameters * * @param string $repetitionRule - rrule field - i.e.: FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU * @return false|array ($repetitionId, $repetitionParam) - false on unrecognized rrule */ public static function fromICalRruleStringToInternalParams($inputRepetitionRule) { if (strlen(trim($inputRepetitionRule)) == 0) { return array(); } // filtering out the UNTIL parameter that we don't use $repetitionRule = preg_replace('!UNTIL=[^;$]+(;)?!', '', $inputRepetitionRule); // filtering out the COUNT parameter that we don't use $repetitionRule = preg_replace('!COUNT=[^;$]+(;)?!', '', $inputRepetitionRule); $repetitionId = 0; $repetitionParam = 0; if (preg_match('!FREQ=WEEKLY;(INTERVAL=([0-9]+))?(BYDAY=([A-Za-z]{2}))?$!', $repetitionRule, $matches)) { $interval = $matches[2]; if ($interval > 1) { // the GCal expression comes like this: FREQ=WEEKLY;INTERVAL=3;BYDAY=SA // but we can safely ignore the BYDAY=SA bit as that inofrmation comes from // the event due date $repetitionId = 12; $repetitionParam = $interval; } else { $weekAbbreviation = strtolower($matches[4]); $weekAbbreviations = array(1 => 'su', 2 => 'mo', 3 => 'tu', 4 => 'we', 5 => 'th', 6 => 'fr', 7 => 'sa'); $repetitionId = array_search($weekAbbreviation, $weekAbbreviations); } if ($interval == 1 && !isset($matches[4])) { $repetitionId = 11; } } else { if ($repetitionRule == 'FREQ=DAILY' || $repetitionRule == 'FREQ=DAILY;INTERVAL=1') { $repetitionId = 8; } else { if (preg_match('!FREQ=WEEKLY;(INTERVAL=([0-9]+);)?BYDAY=MO,TU,WE,TH,FR!', $repetitionRule)) { $repetitionId = 9; } else { if (preg_match('!FREQ=DAILY;INTERVAL=([0-9]+)!', $repetitionRule, $matches)) { $repetitionId = 10; $repetitionParam = $matches[1]; } else { if ($repetitionRule == 'FREQ=WEEKLY' || $repetitionRule == 'FREQ=WEEKLY;INTERVAL=1') { $repetitionId = 11; } else { if (preg_match('!FREQ=MONTHLY;(INTERVAL=([0-9]+);)?BYDAY=([-0-9]+)?(.{2})!', $repetitionRule, $matches)) { // with this case we can handle all // 20 <= repetitionId <= 33 // and // repetitionId >= 40 $repetitionParam = strlen($matches[2]) > 0 ? $matches[2] : 1; // INTERVAL $byday = strlen($matches[3]) > 0 ? $matches[3] : 1; // can be one among -1, 1, 2, 3, 4 corresponding to 'last week', 'first week', ... $repetitionStartingIds = array('1' => 20, '-1' => 27, '2' => 40, '3' => 50, '4' => 60); $dow = $matches[4]; // can be either SU or MO or TU..... $repetitionIncrementalIds = array('SU' => 0, 'MO' => 1, 'TU' => 2, 'WE' => 3, 'TH' => 4, 'FR' => 5, 'SA' => 6); $repetitionId = $repetitionStartingIds[$byday] + $repetitionIncrementalIds[$dow]; } else { if (preg_match('!FREQ=MONTHLY;INTERVAL=1$!', $repetitionRule)) { // the GCal expression comes like this: FREQ=MONTHLY;INTERVAL=X;BYMONTHDAY=1 // but we can safely ignore the BYMONTHDAY=1 bit as that information comes from // the event due date $repetitionId = 13; // this handles also the $repetitionId = 17 } else { if (preg_match('!FREQ=MONTHLY;.*BYMONTHDAY=-1!', $repetitionRule)) { $repetitionId = 18; $repetitionParam = 1; } else { if (preg_match('!FREQ=MONTHLY;.*BYMONTHDAY=-2!', $repetitionRule)) { $repetitionId = 19; $repetitionParam = 1; } else { if (preg_match('!FREQ=MONTHLY;INTERVAL=([0-9]+)!', $repetitionRule, $matches)) { // the GCal expression comes like this: FREQ=MONTHLY;INTERVAL=X;BYMONTHDAY=18 // but we can safely ignore the BYMONTHDAY=18 bit as that information comes from // the event due date $repetitionId = 14; $repetitionParam = $matches[1]; // this handles also the $repetitionId = 17 } else { if (preg_match('!FREQ=MONTHLY;BYMONTHDAY=[0-9]+!', $repetitionRule)) { // the GCal expression comes like this: FREQ=MONTHLY;INTERVAL=X;BYMONTHDAY=18 // but we can safely ignore the BYMONTHDAY=18 bit as that information comes from // the event due date $repetitionId = 14; $repetitionParam = 1; // this handles also the $repetitionId = 17 } else { if ($repetitionRule == 'FREQ=YEARLY' || $repetitionRule == 'FREQ=YEARLY;INTERVAL=1') { $repetitionId = 15; } else { if (preg_match('!FREQ=YEARLY;INTERVAL=([0-9]+)!', $repetitionRule, $matches)) { // the GCal expression comes like this: FREQ=MONTHLY;INTERVAL=X;BYMONTHDAY=1 // but we can safely ignore the BYMONTHDAY=1 bit as that information comes from // the event due date $repetitionId = 16; $repetitionParam = $matches[1]; } else { if ($repetitionRule == 'FREQ=MONTHLY;INTERVAL=([0-9]+);BYMONTHDAY=-1') { $repetitionId = 18; $repetitionParam = $matches[1]; } else { if ($repetitionRule == 'FREQ=MONTHLY;INTERVAL=([0-9]+);BYMONTHDAY=-2') { $repetitionId = 19; $repetitionParam = $matches[1]; } else { if (preg_match('!FREQ=WEEKLY;.*BYDAY=([A-Za-z]+)!', $repetitionRule, $matches)) { // this will be the case with between 1 and 5 weekdays to repeat because // we have handled the other ones in earlier else if's $weekAbbreviations = explode(',', strtolower($matches[1])); $onSun = in_array('su', $weekAbbreviations); $onMon = in_array('mo', $weekAbbreviations); $onTue = in_array('tu', $weekAbbreviations); $onWed = in_array('we', $weekAbbreviations); $onThu = in_array('th', $weekAbbreviations); $onFri = in_array('fr', $weekAbbreviations); $onSat = in_array('sa', $weekAbbreviations); $repetitionId = 34; $repetitionParam = self::fromWeekdaysSetToIntegerForRepetition($onSun, $onMon, $onTue, $onWed, $onThu, $onFri, $onSat); } else { sfErrorNotifier::alert("Couldn't map this rule: " . $inputRepetitionRule); return false; } } } } } } } } } } } } } } } } return array($repetitionId, $repetitionParam); }
$scope = GoogleCalendarInterface::GCAL_INTEGRATION_SCOPE; $secure = false; $session = true; // Redirect the user to the AuthSub server to sign in $authSubUrl = Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session); header("HTTP/1.0 307 Temporary redirect"); header("Location: " . $authSubUrl); exit; } else { try { $client = new Zend_Gdata_HttpClient(); $pathToKey = sfConfig::get('sf_root_dir') . '/' . sfConfig::get('app_googleCalendarIntegration_privateKeyPath'); $client->setAuthSubPrivateKeyFile($pathToKey, null, true); $sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token'], $client); } catch (Exception $e) { sfErrorNotifier::alert("Google Calendar Init: " . $e->getMessage()); $this->redirect('default', array('module' => 'googleCalendarIntegration', 'action' => 'step3Error')); } $redirectUrl = ''; if ($sessionToken) { $loggedInUser = PcUserPeer::getLoggedInUser(); if ($loggedInUser) { $googleCalendarInterface = new GoogleCalendarInterface($loggedInUser); $googleCalendarInterface->resetDbEntry(); $googleCalendarInterface->setSessionToken($sessionToken); } $configuration->loadHelpers('Url'); $redirectUrl = 'http://' . sfConfig::get('app_site_url') . '/' . sfConfig::get('app_accountApp_frontController') . '/googleCalendarIntegration/step3'; } else { // something wrong $configuration->loadHelpers('Url');
public function executeStartupData(sfWebRequest $request) { include_once sfConfig::get('sf_root_dir') . '/apps/api/lib/PlancakeApiServer.class.php'; $loggedInUser = PcUserPeer::getLoggedInUser(); $this->getUser()->setCulture($loggedInUser->getPreferredLanguage()); $userTodayQuote = null; if ($this->getUser()->getAttribute('user_first_login_of_the_day') === 1) { $userTodayQuote = PcQuoteOfTheDayPeer::getUserTodayQuote(); if ($userTodayQuote === null) { sfErrorNotifier::alert("THERE ARE NOT QUOTES LEFT!!!!!!"); } } $quoteContent = ''; $quoteAuthor = ''; if ($userTodayQuote) { $quoteContent = $userTodayQuote->getQuote(); $quoteContentInItalian = $userTodayQuote->getQuoteInItalian(); $quoteAuthor = $userTodayQuote->getQuoteAuthor(); $quoteAuthorInItalian = $userTodayQuote->getQuoteAuthorInItalian(); if ($loggedInUser->isItalian() && $quoteContentInItalian) { $quoteContent = $quoteContentInItalian; } if ($loggedInUser->isItalian() && $quoteAuthorInItalian) { $quoteAuthor = $quoteAuthorInItalian; } } $apiVersion = sfConfig::get('app_api_version'); $lists = PlancakeApiServer::getLists(array('api_ver' => $apiVersion, 'camel_case_keys' => 1)); $tags = PlancakeApiServer::getTags(array('api_ver' => $apiVersion, 'camel_case_keys' => 1)); $repetitionOptions = PlancakeApiServer::getRepetitionOptions(array('api_ver' => $apiVersion)); $userSettings = PlancakeApiServer::getUserSettings(array('api_ver' => $apiVersion, 'camel_case_keys' => 1)); $breakingNewsId = ''; $breakingNewsHeadline = ''; $breakingNewsLink = ''; if ($breakingNews = $loggedInUser->getBreakingNews()) { $breakingNewsId = $breakingNews->getId(); $breakingNewsHeadline = $breakingNews->getHeadline(); $breakingNewsLink = $breakingNews->getLink(); } $data = array('isPublicRelease' => (int) defined('PLANCAKE_PUBLIC_RELEASE'), 'isFirstDesktopLogin' => (int) $this->getUser()->getAttribute('user_still_to_load_desktop_app'), 'quoteAuthor' => $quoteAuthor, 'quoteContent' => $quoteContent, 'breakingNewsId' => $breakingNewsId, 'breakingNewsHeadline' => $breakingNewsHeadline, 'breakingNewsLink' => $breakingNewsLink, 'showExpiringSubscriptionAlert' => (int) $loggedInUser->isExpiringSubscriptionAlertToShow(), 'isSubscriptionExpired' => (int) $loggedInUser->isSubscriptionExpired()); $config = array('maxListsForFreeAccount' => sfConfig::get('app_site_maxListsForNonSupporter'), 'maxTagsForFreeAccount' => sfConfig::get('app_site_maxTagsForNonSupporter'), 'supportEmailAddress' => sfConfig::get('app_emailAddress_support'), 'custom' => $loggedInUser->getId() == 4 ? 1 : 0); // this 'custom' key is a temporal thing if (stripos($request->getUri(), '/mobile') === FALSE) { // the request doesn't come from the mobile app $this->getUser()->setAttribute('user_still_to_load_desktop_app', 0); } $lang = null; $strings = PcStringPeer::getWebAppStrings(); $i = 0; foreach ($strings as $string) { $lang[$string->getId()] = __($string->getId()); } $startupData = array('hideableHintsSetting' => $loggedInUser->getHideableHintsSetting(), 'lists' => $lists, 'tags' => $tags, 'repetitionOptions' => $repetitionOptions, 'userSettings' => $userSettings, 'data' => $data, 'config' => $config, 'lang' => $lang); if ($request->isXmlHttpRequest()) { return $this->renderJson($startupData); } }
/** * If the email is too big (probably because of attachments), it records * only the beginning of it * * @param string $errorMessage * @param string $emailPath */ private function handleFault($errorMessage, $emailPath) { $this->log($errorMessage); sfErrorNotifier::alert($errorMessage); $emailFileSize = filesize($emailPath); if ($emailFileSize < 32000) { $description = file_get_contents($emailPath); } else { $description = "The email was too big (probably because of attachment). Here is the beginning of it: \n\n"; $description .= shell_exec("cat {$emailPath} | head -100"); } $watchdog = new PcWatchdog(); $watchdog->setType('email-to-inbox')->setDescription($description)->save(); if (is_file($emailPath)) { unlink($emailPath); } }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeError404(sfWebRequest $request) { sfErrorNotifier::alert('error404'); }
public static function handleException($e) { sfErrorNotifier::notifyException($e); }
/** * Returns the repetition expression for the task (if any), ready to be displayed to the user. * * @return string */ public function getRepetitionHumanExpression() { if (!($repetitionId = $this->getRepetitionId())) { return ''; } else { $repetition = PcRepetitionPeer::retrieveByPk($repetitionId); if (!$repetition->needsParam()) { return $repetition->getLocalizedHumanExpression(); } else { $repetitionParam = $this->getRepetitionParam(); if ($repetition->getSpecial() != 'selected_wkdays') { if (!$repetition->isParamCardinal()) { $repetitionParam = PcUtils::getOrdinalFromCardinal($repetitionParam); } $repetitionString = str_replace(__('ACCOUNT_TASK_REPETITION_SELECT_LATER'), $repetitionParam, $repetition->getLocalizedHumanExpression(), $count); if (!$count) { sfErrorNotifier::alert('The [select later] string has changed'); } else { return $repetitionString; } } else { $weekdaysSet = DateFormat::fromIntegerToWeekdaysSetForRepetition($repetitionParam); $selectedWeekdays = array(); foreach ($weekdaysSet as $k => $v) { if ($v) { $selectedWeekdays[] = __('ACCOUNT_DOW_ON_PREPOSITION') . ' ' . PcUtils::fromAbbreviationToWeekday($k); } } return implode(", ", $selectedWeekdays); } } } }