예제 #1
0
 public function run($siteID, $args)
 {
     Task::setName('Calendar Reminders');
     Task::setDescription('Send out reminder e-mails from the CATS calendar.');
     $calendar = new Calendar(0);
     //Check for reminders that need to be sent out.
     $dueEvents = $calendar->getAllDueReminders();
     // Do/log nothing if no events exist
     if (!count($dueEvents)) {
         return TASKRET_SUCCESS_NOLOG;
     }
     foreach ($dueEvents as $index => $data) {
         $emailSubject = 'CATS Event Reminder: ' . $data['title'];
         $emailContents = $GLOBALS['eventReminderEmail'];
         $stringsToFind = array('%FULLNAME%', '%NOTES%', '%EVENTNAME%', '%DUETIME%');
         $replacementStrings = array($data['enteredByFirstName'] . ' ' . $data['enteredByLastName'], $data['description'], $data['title'], self::_getReminderTimeString($data['reminderTime']));
         $emailContents = str_replace($stringsToFind, $replacementStrings, $emailContents);
         $emailDestination = $data['reminderEmail'];
         // SEND E-Mail here
         $calendar->sendEmail($data['siteID'], 0, $emailDestination, $emailSubject, $emailContents);
         // Remove alert.
         $calendar->updateEventDisableReminder($data['eventID']);
     }
     // Set the response the task wants logged
     $this->setResponse(sprintf('E-mailed %d calendar reminders.', count($dueEvents)));
     return TASKRET_SUCCESS;
 }
예제 #2
0
 public function run($siteID, $args)
 {
     Task::setName('Sphinx Rebuild, Delta, Status');
     Task::setDescription('Rebuilds the index, the delta and status of Sphinx indexer.');
     $response = 'The following tasks were completed successfully: ';
     // Nightly Rebuild of entire Sphinx index at 01:00AM CST
     if (self::getHour() == 1 && self::getMinute() == 0) {
         if (!system($script = sprintf('%s/scripts/sphinx_rotate.sh', ASPUtility::getEnvironmentValue('CATS_PATH')), $result)) {
             $this->setResponse(sprintf('Unable to execute "%s": ', $script) . $result);
             return TASKRET_ERROR;
         }
         $response .= ' * Rebuilt the entire Sphinx index';
     }
     // Check Sphinx Status every 5 minutes
     if (!(self::getMinute() % 5)) {
         if (!system($script = sprintf('%s %s/scripts/sphinxtest.php', ASPUtility::getEnvironmentValue('PHP_PATH'), ASPUtility::getEnvironmentValue('CATS_PATH')), $result)) {
             $this->setResponse(sprintf('Unable to execute "%s": ', $script) . $result);
             return TASKRET_ERROR;
         }
         if (!system($script = sprintf('%s/scripts/sphinx_restart.sh', ASPUtility::getEnvironmentValue('CATS_PATH')), $result)) {
             $this->setResponse(sprintf('Unable to execute "%s": ', $script) . $result);
             return TASKRET_ERROR;
         }
         $response .= ' * Checked Sphinx status';
     }
     // Update Sphinx DELTA index every minute
     if (!system($script = sprintf('%s/scripts/sphinx_update_delta.sh', ASPUtility::getEnvironmentValue('CATS_PATH')), $result)) {
         $this->setResponse(sprintf('Unable to execute "%s": ', $script) . $result);
         return TASKRET_ERROR;
     }
     $response .= ' * Updated the Delta';
     $this->setResponse($response);
     return TASKRET_SUCCESS;
 }
예제 #3
0
 public function run($siteID, $args)
 {
     Task::setName('CleanExceptions');
     Task::setDescription('Clean up the exceptions log.');
     $db = DatabaseConnection::getInstance();
     $sql = sprintf("DELETE FROM\n                exceptions\n             WHERE\n                DATEDIFF(NOW(), exceptions.date) > %s", EXCEPTIONS_TTL_DAYS);
     if (!($rs = $db->query($sql))) {
         $message = 'Query "' . $sql . '" failed!';
         $ret = TASKRET_ERROR;
     } else {
         $num = $db->getAffectedRows();
         if ($num > 0) {
             $message = 'Cleaned up ' . number_format($num, 0) . ' exception logs.';
             $ret = TASKRET_SUCCESS;
         } else {
             // Do not log if nothing was done
             $message = 'No logs were cleaned.';
             $ret = TASKRET_SUCCESS_NOLOG;
         }
     }
     // Set the response the task wants logged
     $this->setResponse($message);
     // Return one of the above TASKRET_ constants.
     return $ret;
 }
예제 #4
0
 public static function createTasksFromData($data, $week = null)
 {
     $result = array();
     foreach ($data as $index => $taskArray) {
         $task = new Task();
         $task->setTime($taskArray['time']);
         $task->setName($taskArray['name']);
         $task->setIndex($index);
         $task->setWeek($week);
         $result[$index] = $task;
     }
     return $result;
 }
예제 #5
0
 public function run($siteID, $args)
 {
     Task::setName('Sample Non-Recurring Task');
     Task::setDescription('This is the description of this sample task.');
     /**
      * The following are the possible return values of this function.
      * You should put the code you want to run in this function.
      */
     switch (rand(0, 3)) {
         /**
          * TASKRET_ERROR
          *   This task will not be attempted again. It will be marked as an error
          *   and the development team will be notified.
          */
         case 0:
             $message = 'Error';
             $ret = TASKRET_ERROR;
             break;
             /**
              * TASKRET_FAILURE
              *   This task will be tried again a few times. If it continues to fail, it
              *   will be marked as an error (see above).
              */
         /**
          * TASKRET_FAILURE
          *   This task will be tried again a few times. If it continues to fail, it
          *   will be marked as an error (see above).
          */
         case 1:
             $message = 'Failure (will try again)';
             $ret = TASKRET_FAILURE;
             break;
             /**
              * TASKRET_SUCCESS
              *   This task completed successfully and will be logged.
              */
         /**
          * TASKRET_SUCCESS
          *   This task completed successfully and will be logged.
          */
         case 2:
             $message = 'Success';
             $ret = TASKRET_SUCCESS;
             break;
             /**
              * TASKRET_SUCCESS_NOLOG
              *   The task completed successfully but will not save a log.
              */
         /**
          * TASKRET_SUCCESS_NOLOG
          *   The task completed successfully but will not save a log.
          */
         default:
             $message = 'Success (no log)';
             $ret = TASKRET_SUCCESS_NOLOG;
             break;
     }
     // Set the response the task wants logged
     $this->setResponse($message);
     // Return one of the above TASKRET_ constants.
     return $ret;
 }
예제 #6
0
 public function executeAddTask()
 {
     $project = ProjectPeer::retrieveByUuid($this->getRequestParameter('slug'));
     // TODO: make sure user is a member of project
     $this->forward404Unless($project, 'Project not found, or user is not member, unable to add task');
     $this->forward404Unless($user = sfGuardUserProfilePeer::retrieveByUuid($this->getRequestParameter('task_user'), 'Unable to retrieve user'));
     // TODO: add validation for task input
     $task = new Task();
     $task->setProjectId($project->getId());
     $task->setOwnerId($this->getUser()->getProfile()->getUserID());
     $task->setName($this->getRequestParameter('name', 'Task Name'));
     $task->setDescription($this->getRequestParameter('description', 'Task Description'));
     if ($this->getRequestParameter('begin')) {
         list($d, $m, $y) = sfI18N::getDateForCulture($this->getRequestParameter('begin'), $this->getUser()->getCulture());
         $task->setBegin("{$y}-{$m}-{$d}");
     }
     if ($this->getRequestParameter('finish')) {
         list($d, $m, $y) = sfI18N::getDateForCulture($this->getRequestParameter('finish'), $this->getUser()->getCulture());
         $task->setFinish("{$y}-{$m}-{$d}");
     }
     $task->setStatus(sfConfig::get('app_task_status_open'));
     $task->setPriority($this->getRequestParameter('priority'));
     $task->save();
     //if ($user != null) $task->addUser($user->getUserId());
     $task->addUser($user->getUserId());
     $this->redirect('@show_project_tasks?tab=tasks&project=' . $project->getSlug());
 }
예제 #7
0
 /**
  * Get task by id
  * @param int $id
  * @return Task null
  */
 public function getTask($id)
 {
     $result = $this->db->query("SELECT * FROM tasks WHERE id = {$id} LIMIT 1");
     foreach ($result as $key => $row) {
         $task = new Task();
         $task->setId($row['id']);
         $task->setName($row['name']);
         $task->setParameters($row['parameters']);
         $task->setStatus($row['status']);
         return $task;
     }
     return null;
 }
 function importPendingEmailToTaskList(&$incoming_mail, &$project, &$user, $page_id, $comment)
 {
     //$link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
     //mysql_select_db(DB_NAME, $link);
     //mysql_query("insert into testing (date_added, content) values (now(), 'in task list adde func:Page " . $page_id . " / comment: " . $comment->getId() . "')");
     //mysql_query("insert into testing (date_added, content) values (now(), '" . mysql_real_escape_string($incoming_mail->getSubject()) . "')");
     //EOF:mod 20120820
     list($user_name, $priority) = explode('-', $incoming_mail->getSubject());
     $user_name = trim($user_name);
     $priority = trim($priority);
     $name_parts = explode(' ', $user_name);
     list($first_name, $last_name) = $name_parts;
     //mysql_query("insert into testing (date_added, content) values (now(), '" . mysql_real_escape_string($priority) . "')");
     //BOF:mod 20120820
     /*
     //EOF:mod 20120820
     $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
     mysql_select_db(DB_NAME, $link);
     $query = "select id from healingcrystals_users where first_name='" . mysql_real_escape_string($first_name) . "' " . (!empty($last_name) ? " and last_name='" . mysql_real_escape_string($last_name) . "' " : "");
     $result = mysql_query($query, $link);
     if (mysql_num_rows($result)){
     		$info = mysql_fetch_assoc($result);
     		$user_id = $info['id'];
     		$task_meant_for_user = Users::findById($user_id);
     		$page_title = $task_meant_for_user->getName() . ' - Task List';
     		//echo $page_title . '<br/>';
     		$query2 = "select id from healingcrystals_project_objects where type='Page' and project_id='" . TASK_LIST_PROJECT_ID . "' and name='" . mysql_real_escape_string($page_title) . "'";
     		//echo $query2 . '<br/>';
     		$result2 = mysql_query($query2,$link);
     		if (mysql_num_rows($result2)){
     			$info2 = mysql_fetch_assoc($result2);
     			$page_id = $info2['id'];
     		} else {
     			$query3 = "select id from healingcrystals_project_objects where type='Category' and module='pages' and project_id='" . TASK_LIST_PROJECT_ID . "' and name='General'";
     			//echo $query3 . '<br/>';
     			$page_category = mysql_query($query3, $link);
     			$page_category_info = mysql_fetch_assoc($page_category);
     			$category_id = $page_category_info['id'];
     			//echo $category_id . '<br/>';
     
     			$page_data = array(
     				'type' => 'Page',
     				'module' => 'pages',
     				'visibility' => VISIBILITY_NORMAL,
     				'name' => $page_title,
     				'body' => 'Auto-generated Task List Page',
     				'integer_field_1' => '1',
     			);
     			//print_r($page_data);
     			//db_begin_work();
     			$page = new Page();
     			$page->setAttributes($page_data);
     			$page->setProjectId(TASK_LIST_PROJECT_ID);
     			$page->setCreatedBy($user);
     			$page->setState(STATE_VISIBLE);
     			$page->setParentId($category_id);
     			$page->save();
     			$page->ready();
     			$page_id = $page->getId();
     		}
     }
     mysql_close($link);
     //BOF:mod 20120820
     */
     //EOF:mod 20120820
     $task = new Task();
     $task->setProjectId($project->getId());
     $task->setParentId($page_id);
     $task->setParentType('Page');
     $task->setCreatedBy($user);
     $task->setCreatedOn($incoming_mail->getCreatedOn());
     $task->setVisibility(VISIBILITY_NORMAL);
     $task->setState(STATE_VISIBLE);
     $task->setSource(OBJECT_SOURCE_EMAIL);
     if (!empty($priority)) {
         $constant_name = 'PRIORITY_' . strtoupper(str_replace(' ', '', $priority));
         $priority_val = '';
         $priority_val_set = false;
         if (defined($constant_name)) {
             switch ($constant_name) {
                 case 'PRIORITY_HOLD':
                     $priority_val = '-4';
                     $priority_val_set = true;
                     break;
                     //BOF:mod 20121107
                     /*
                     //EOF:mod 20121107
                     case 'PRIORITY_ONGOING':
                     	$priority_val = '-3';
                     	$priority_val_set = true;
                     	break;
                     //BOF:mod 20121107
                     */
                     //EOF:mod 20121107
                 //BOF:mod 20121107
                 /*
                 //EOF:mod 20121107
                 case 'PRIORITY_ONGOING':
                 	$priority_val = '-3';
                 	$priority_val_set = true;
                 	break;
                 //BOF:mod 20121107
                 */
                 //EOF:mod 20121107
                 case 'PRIORITY_LOWEST':
                     $priority_val = '-2';
                     $priority_val_set = true;
                     break;
                 case 'PRIORITY_LOW':
                     $priority_val = '-1';
                     $priority_val_set = true;
                     break;
                 case 'PRIORITY_NORMAL':
                     $priority_val = '0';
                     $priority_val_set = true;
                     break;
                 case 'PRIORITY_HIGH':
                     $priority_val = '1';
                     $priority_val_set = true;
                     break;
                 case 'PRIORITY_HIGHEST':
                     $priority_val = '2';
                     $priority_val_set = true;
                     break;
                     //BOF:mod 20121107
                 //BOF:mod 20121107
                 case 'PRIORITY_URGENT':
                     $priority_val = '3';
                     $priority_val_set = true;
                     break;
                     //EOF:mod 20121107
             }
             if ($priority_val_set) {
                 $task->setPriority($priority_val);
             }
         }
     }
     $task->setName($incoming_mail->getSubject());
     $amended_body = '';
     //BOF:mod 20120820
     if (empty($comment)) {
         if (strpos($incoming_mail->getSubject(), '{') !== false) {
             $amended_body .= substr($incoming_mail->getSubject(), 0, strrpos($incoming_mail->getSubject(), '{'));
         } else {
             $amended_body .= $incoming_mail->getBody();
         }
     } else {
         if (strpos($incoming_mail->getSubject(), '{') !== false) {
             $parent = $comment->getParent();
             $url = $parent->getViewUrl() . '#comment' . $comment->getId();
             $amended_body .= substr($incoming_mail->getSubject(), 0, strrpos($incoming_mail->getSubject(), '{')) . '<br/><a href="' . $url . '">View Task in Full</a>';
         } else {
             $temp_body = strip_tags($incoming_mail->getBody());
             $chars_len = strlen($temp_body);
             //if ($chars_len > 150){
             if ($chars_len > 525) {
                 //mysql_query("insert into testing (date_added, content) values (now(), 'greater than 150 block')");
                 //$url = $comment->getRealViewUrl();
                 $parent = $comment->getParent();
                 $url = $parent->getViewUrl() . '#comment' . $comment->getId();
                 //mysql_query("insert into testing (date_added, content) values (now(), '" . mysql_real_escape_string($url) . "')");
                 //$amended_body .= substr($temp_body, 0, 150) . '.. <br/><a href="' . $url . '">View Task in Full</a>';
                 $amended_body .= substr($temp_body, 0, 525) . '.. <br/><a href="' . $url . '">View Task in Full</a>';
             } else {
                 $amended_body .= $incoming_mail->getBody();
             }
         }
         //mysql_query("insert into testing (date_added, content) values (now(), '" . mysql_real_escape_string($amended_body) . "')");
         $attachments = $comment->getAttachments();
         if (is_foreachable($attachments)) {
             $amended_body .= '<br/>Attachments:<br/>';
             foreach ($attachments as $attachment) {
                 $amended_body .= '<a href="' . $attachment->getViewUrl() . '">' . $attachment->getName() . '</a><br/>';
             }
         }
     }
     $task->setBody($amended_body);
     //IncomingMailImporter::attachFilesToProjectObject($incoming_mail, $task);
     $save = $task->save();
     if ($save && !is_error($save)) {
         //$subscibed_users = array($project->getLeaderId());
         //if (instance_of($user, 'User')) {
         // $subscibed_users[] = $user->getId();
         //} // if
         //Subscriptions::subscribeUsers($subscibed_users, $ticket);
         $task->ready();
         //mysql_query("insert into testing (date_added, content) values (now(), 'in task list adde func end: " . $task->getId() . "')");
         return $task;
     }
     // if
     return $save;
     //mysql_close($link);
 }