예제 #1
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;
 }
예제 #2
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;
 }
예제 #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
 function testSetDescription()
 {
     //Arrange
     $description = "Do dishes.";
     $test_task = new Task($description);
     //Act
     $test_task->setDescription("Drink coffee.");
     $result = $test_task->getDescription();
     //Assert
     $this->assertEquals("Drink coffee.", $result);
 }
예제 #5
0
 function test_task_setDescription()
 {
     //Arrange
     $description = "Wash the dog";
     $test_task = new Task($description);
     //Act
     $test_task->setDescription("Feed dog");
     $result = $test_task->getDescription();
     //Assert
     $this->assertEquals("Feed dog", $result);
 }
예제 #6
0
 function test_setDescription()
 {
     //Arrange
     $description = "Do dishes.";
     $due_date = "1234-12-12";
     $task = new Task($description, $due_date);
     //Act
     $task->setDescription("Drink coffee.");
     $result = $task->getDescription();
     //Assert
     $this->assertEquals("Drink coffee.", $result);
 }
예제 #7
0
 function testSetDescription()
 {
     // Arrange
     $description = "Wash the dog";
     $id = 1;
     $due_date = "2016-02-29";
     $test_task = new Task($description, $id, $due_date);
     $test_task->save();
     // Act
     $test_task->setDescription("Feed the dog");
     $result = $test_task->getDescription();
     // Assert
     $this->assertEquals("Feed the dog", $result);
 }
예제 #8
0
 public function executeUpdate()
 {
     $jira = new sfJiraPlugin($this->getUser()->getProfile()->getJiraLogin(), $this->getUser()->getProfile()->getJiraPassword());
     $aProjects = $jira->getProjects();
     foreach ($aProjects as $project) {
         #var_dump( $project );
         $c = new Criteria();
         $c->add(ProjectPeer::USER_ID, $this->getUser()->getProfile()->getId());
         $c->add(ProjectPeer::KEY, $project->key);
         $p = ProjectPeer::doSelectOne($c);
         $c = new Criteria();
         $c->add(UserPeer::JIRA_LOGIN, $project->lead);
         $u = UserPeer::doSelectOne($c);
         if (empty($p)) {
             $p = new Project();
             $p->setKey($project->key);
             $p->setLeadId(!empty($u) ? $u->getId() : null);
             $p->setUserId($this->getUser()->getProfile()->getId());
             $p->setName($project->name);
             $p->setUpdated(date('r'));
             $p->save();
         }
         $issues = $jira->getIssuesForProject($p->getKey());
         foreach ($issues as $issue) {
             #die($p->getKey());
             if ($issue->assignee == $this->getUser()->getProfile()->getJiraLogin()) {
                 $c = new Criteria();
                 $c->add(TaskPeer::KEY, $issue->key);
                 $t = TaskPeer::doSelectOne($c);
                 if (empty($t)) {
                     $c = new Criteria();
                     $c->add(UserPeer::JIRA_LOGIN, $issue->reporter);
                     $u = UserPeer::doSelectOne($c);
                     $t = new Task();
                     $t->setProjectId($p->getId());
                     $t->setTitle($issue->summary);
                     $t->setDescription($issue->description);
                     $t->setKey($issue->key);
                     $t->setUpdated(date('r'));
                     $t->setStatusId($issue->status);
                     $t->setPriorityId($issue->priority);
                     $t->setLeadId(!empty($u) ? $u->getId() : null);
                     $t->save();
                 }
             }
         }
     }
     $this->redirect('@homepage');
     return sfView::NONE;
 }
예제 #9
0
 function testSetDescription()
 {
     //Arrange
     $description = "Do Dishes";
     $due_date = null;
     $completed = 0;
     $id = 1;
     $test_task = new Task($description, $due_date, $completed, $id);
     //Act
     //Set the task to a new task to see if the task has changed
     $test_task->setDescription("Drink coffee");
     $result = $test_task->getDescription();
     //Assert
     $this->assertEquals("Drink coffee", $result);
 }
예제 #10
0
 function testSetDescription()
 {
     //Arrange
     $name = "School stuff";
     $id = null;
     $test_category = new Category($name, $id);
     $test_category->save();
     $description = "Do dishes.";
     $category_id = $test_category->getId();
     $test_task = new Task($description, $id, $category_id);
     //Act
     $test_task->setDescription("Drink coffee.");
     $result = $test_task->getDescription();
     //Assert
     $this->assertEquals("Drink coffee.", $result);
 }
예제 #11
0
 /**
  * @param $taskName
  * @param $taskDesc
  * @param $taskDueDate
  * @param $taskStatus
  * @param null $userId
  * @param null $projectId
  * @return bool
  * @throws \Exception
  */
 public function createTask($taskName, $taskDesc, $taskDueDate, $taskStatus, $userId = null, $projectId = null)
 {
     $task = new Task();
     $task->setTitle($taskName);
     $task->setDescription($taskDesc);
     $task->setDueDate(new \DateTime($taskDueDate));
     $task->setStatus($taskStatus);
     if ($projectId) {
         $project = $this->em->getRepository('AppBundle:Project');
         $task->setProject($project->find($project_id));
     }
     if ($userId) {
         $user = $this->em->getRepository('AppBundle:User');
         $task->setUser($user->find($useId));
     }
     try {
         $this->em->persist($task);
         $this->em->flush();
         return true;
     } catch (\Exception $e) {
         throw $e;
     }
 }
예제 #12
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;
 }
예제 #13
0
파일: pantr.php 프로젝트: pago/pantr
 /**
  * Register a new task and return it for further specification.
  *
  * This is the main entrance point for pantrfiles.
  * <code>pantr::task('foo', 'some description')
  * ->run(function() { pantr::writeln('Hello World!'); });
  *
  * This method is heavily overloaded. You can invoke it in any of the following ways:
  * - task(string $name): This will create a new task or return an existing one
  * - task(string $name, string $desc): This will create a new task with the specified
  * 				name and description or set the description of an existing task
  * - task(string $name, callable $fn): Creates a new task or updates the tasks execution code
  * - task(string $name, string $desc, callable $fn): Create or redefine an existing task
  *
  * @return Task A new or existing task with the specified $name.
  */
 public static function task($name, $fnOrDesc = null, $fn = null)
 {
     if (isset(self::$taskRepository[$name])) {
         $task = self::$taskRepository[$name];
         if (!is_null($fnOrDesc)) {
             if (is_callable($fnOrDesc)) {
                 $task->run($fnOrDesc);
             } else {
                 if (is_string($fnOrDesc)) {
                     $task->setDescription($fnOrDesc);
                 } else {
                     throw new \InvalidArgumentException('Second parameter must be either string or callable');
                 }
             }
         }
         if (!is_null($fn)) {
             if (is_callable($fn)) {
                 $task->run($fn);
             } else {
                 throw new \InvalidArgumentException('Third parameter must be callable!');
             }
         }
     } else {
         $task = new Task($name);
         if (is_null($fnOrDesc) && is_null($fn)) {
             $task->setDescription('n/a');
         }
         if (is_null($fn) && is_callable($fnOrDesc)) {
             $task->run($fnOrDesc);
         } else {
             if (is_string($fnOrDesc)) {
                 $task->setDescription($fnOrDesc);
             }
         }
         if (!is_null($fn) && is_callable($fn)) {
             $task->run($fn);
         }
         self::$taskRepository->registerTask($task);
     }
     return $task;
 }
예제 #14
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());
 }
예제 #15
0
if (isset($_POST['action']) and is_ajax()) {
    if (Authentication::is_login_required()) {
        echo json_encode(array('status' => 'error', 'reason' => 'Your session has expired. Please log in again!'));
        die;
    }
    try {
        if ($_POST['action'] == "new_task") {
            if (isset($_POST['task-desc'])) {
                if (empty(trim($_POST['task-desc']))) {
                    echo json_encode(array('status' => 'validation', 'reason' => 'Your task description is empty!'));
                } else {
                    if (strlen($_POST['task-desc']) > 80) {
                        echo json_encode(array('status' => 'validation', 'reason' => 'Your task description is too long!'));
                    } else {
                        $task = new Task();
                        $task->setDescription($_POST['task-desc']);
                        $task->setTaskListId($_POST['id']);
                        $task->save();
                        echo json_encode(array('status' => 'success', 'task-id' => $task->getId()));
                    }
                }
            } else {
                echo json_encode(array('status' => 'error', 'reason' => 'Task description not supplied.'));
            }
        } else {
            if ($_POST['action'] == "new_list") {
                if (isset($_POST['name'])) {
                    if (empty(trim($_POST['name']))) {
                        echo json_encode(array('status' => 'validation', 'reason' => 'Your task list name is empty!'));
                        die;
                    }
예제 #16
0
         if ($leader->getNotifyMakeTaskLeader()) {
             // compose email
             $body = "<p>" . formatUserLink(Session::getUserID()) . ' made you the leader of the task <a href="' . Url::task($taskID) . '">' . $task->getTitle() . '</a> in the project ' . formatProjectLink($project->getID()) . '.</p>';
             $email = array('to' => $leader->getEmail(), 'subject' => '[' . PIPELINE_NAME . '] You are now leading a task in ' . $project->getTitle(), 'message' => $body);
             // send email
             Email::send($email);
         }
     }
     // set flag
     $modified = true;
 }
 // is description modified?
 if ($description != $task->getDescription()) {
     // save changes
     $oldDescription = $task->getDescription();
     $task->setDescription($description);
     $task->save();
     // log it
     $logEvent = new Event(array('event_type_id' => 'edit_task_description', 'project_id' => $project->getID(), 'user_1_id' => Session::getUserID(), 'item_1_id' => $task->getID(), 'data_1' => $oldDescription, 'data_2' => $description));
     $logEvent->save();
     // set flag
     $modified = true;
 }
 // is status modified?
 if ($status != $task->getStatus()) {
     // save changes
     $oldStatus = $task->getStatus();
     $task->setStatus($status);
     $task->save();
     // log it
     $logEvent = new Event(array('event_type_id' => 'edit_task_status', 'project_id' => $project->getID(), 'user_1_id' => Session::getUserID(), 'item_1_id' => $task->getID(), 'data_1' => $oldStatus, 'data_2' => $status));