protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $this->logSection('repeater', 'Getting repeaters'); $repeaters = Doctrine_Query::create()->from('TicketRepeater r')->addWhere('r.isClosed = ?', false)->addWhere('r.next_start <= ?', date('Y-m-d H:i:s'))->leftJoin('r.Responsibles')->leftJoin('r.Observers')->execute(); $this->logSection('repeater', sprintf('Found %d possibly not resheduled repeaters', count($repeaters))); foreach ($repeaters as $repeater) { $this->logSection('repeater', sprintf('Processing repeater #%d', $repeater->getId())); $ticketNextPlannedStartTime = strtotime($repeater->getNextStart()); $createBeforeDays = $repeater->getCreateBeforeDays(); $isTicketAlreadyCreated = Doctrine_Query::create()->from('Ticket t')->addWhere('t.planned_start = ?', $repeater->getNextStart())->count() === 1; $createBeforeDaysFulfilled = strtotime('-' . $createBeforeDays . ' days', $ticketNextPlannedStartTime) <= time(); if (!$isTicketAlreadyCreated and $createBeforeDaysFulfilled) { $this->logSection('repeater', sprintf('Creating ticket for #%d', $repeater->getId())); $deadlineDays = $repeater->getDeadlineDays(); $deadlineTime = strtotime('+' . $deadlineDays . ' days', $ticketNextPlannedStartTime); $ticket = Ticket::createFromArray(['name' => $repeater->getName(), 'company_id' => $repeater->getCompanyId(), 'category_id' => $repeater->getCategoryId(), 'description' => $repeater->getDescription(), 'planned_start' => date('Y-m-d H:i:s', $ticketNextPlannedStartTime), 'deadline' => date('Y-m-d H:i:s', $deadlineTime), 'repeater_id' => $repeater->getId(), 'created_by' => $repeater->getInitiatorId()]); $ticket->save(); $ticket->link('Responsibles', array_map(function ($user) { return $user['id']; }, $repeater->getResponsibles()->toArray())); $ticket->link('Observers', array_map(function ($user) { return $user['id']; }, $repeater->getObservers()->toArray())); $ticket->save(); $this->logSection('repeater', sprintf('Created ticket #%d for repeater #%d', $ticket->getId(), $repeater->getId())); $comment = Comment::createFromArray(['skip_notification' => true, 'ticket_id' => $ticket->getId(), 'text' => 'Заявка относится к регламентной работе ##' . $repeater->getId(), 'created_by' => $repeater->getInitiatorId()]); $comment->save(); $nextStartTime = strtotime('+' . $repeater->getRepeatedEveryDays() . ' days', strtotime($repeater->getNextStart())); $repeater->setNextStart(date('Y-m-d H:i:s', $nextStartTime)); $repeater->save(); $this->logSection('repeater', sprintf('Sheduled repeater #%d to %s', $repeater->getId(), $repeater->getNextStart())); } } }
function create() { $comment = Comment::createFromArray('Comment', $this->parameters['comment']); if ($comment->save()) { $this->redirect('/posts/' . $comment->post_id); return; } $this->vars['comment'] = $comment; }
public function executePost(sfWebRequest $request) { // drop self sent emails if ($request->getParameter('sender') === '*****@*****.**') { die('dropped self sent email'); } $result = []; // get sender user $from = Doctrine_Query::create()->from('sfGuardUser u')->addWhere('u.email_address = ?', strtolower($request->getParameter('sender')))->fetchOne(); $ticket = null; $subject = $request->getParameter('subject'); // search for ticket id in subject and search for such ticket in db if (preg_match('/\\[F1LAB\\-HLPDSK\\-([\\d]+)\\]/', $subject, $mathed)) { $result[] = 'matched magic subject'; $ticket = Doctrine_Query::create()->from('Ticket t')->addWhere('t.id = ?', $mathed[1])->limit(1)->fetchOne(); if ($ticket) { $result[] = 'ticket found'; // ticket found, reopen if needed and add comment $comment = Comment::createFromArray(['ticket_id' => $ticket->getId(), 'text' => $request->getParameter('body-plain'), 'created_by' => $from ? $from->getId() : 82]); if ($ticket->getIsClosed()) { $comment->setChangedTicketStateTo('opened'); $ticket->setIsClosed(false)->save(); } $comment->save(); $result[] = 'comment created'; } } // no such ticket found, creating if (!$ticket) { $result[] = 'no such ticket'; $ticket = Ticket::createFromArray(['name' => $subject, 'company_id' => $from && $from->getGroups() && $from->getGroups()->getFirst() ? $from->getGroups()->getFirst() : 1, 'description' => str_replace("\n", "<br/>\n", $request->getParameter('body-plain')), 'created_by' => $from ? $from->getId() : 82, 'real_sender' => $from ? null : $request->getParameter('sender')]); $ticket->save(); $result[] = 'ticket created'; } // adding files to ticket if (count($_FILES)) { $destination = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . 'comment-attachments' . DIRECTORY_SEPARATOR; foreach ($_FILES as $file) { $nameParts = explode('.', $file['name']); $extension = array_pop($nameParts); $newName = uniqid() . '.' . $extension; if (move_uploaded_file($file['tmp_name'], $destination . $newName)) { $comment = Comment::createFromArray(['ticket_id' => $ticket->getId(), 'text' => 'Добавлен файл из письма: ' . $file['name'], 'attachment' => $newName, 'created_by' => $from ? $from->getId() : 82, 'skip_notification' => true]); $comment->save(); $result[] = 'comment with file created'; } } } die(print_r($result, 1)); }
public function preDqlDelete($event) { $parameters = $event->getQuery()->getParams()['where']; $ticketId = array_shift($parameters); $usersIds = $parameters; foreach ($usersIds as $userId) { $observer = Doctrine_Core::getTable('sfGuardUser')->find($userId); // add comment to ticket if ($observer) { $comment = Comment::createFromArray(['ticket_id' => $ticketId, 'created_by' => sfContext::getInstance()->getUser()->getGuardUser()->getId(), 'text' => 'Убрал из списка наблюдателей ' . $observer, 'skip_notification' => true]); $comment->save(); } } }
public function executeApply(sfWebRequest $request) { $ticket = Doctrine_Core::getTable('Ticket')->findOneById($request->getParameter('id')); $this->forward404Unless($ticket); $applier = Comment::createFromArray(['changed_ticket_state_to' => 'applied', 'ticket_id' => $ticket->getId(), 'text' => 'Принял в работу']); $applier->save() and $this->redirect($request->getReferer()); }
public function preDelete($event) { $responsible = Doctrine_Core::getTable('sfGuardUser')->find($this->getUserId()); $comment = Comment::createFromArray(['ticket_id' => $this->getTicketId(), 'created_by' => sfContext::getInstance()->getUser()->getGuardUser()->getId(), 'text' => 'Убрал из списка ответственных ' . $responsible, 'skip_notification' => true]); $comment->save(); }
public function executeIAmNotResponsibleForThis(sfWebRequest $request) { $this->getResponse()->setHeaderOnly(true); $this->forward404Unless($this->getUser()->isAuthenticated()); $json = file_get_contents('php://input'); $data = json_decode($json, true); $this->forward404Unless($json and $data and $data['ticketId'] and $data['reason']); $ref = Doctrine_Query::create()->from('RefTicketResponsible ref')->addWhere('ref.ticket_id = ?', $data['ticketId'])->addWhere('ref.user_id = ?', $this->getUser()->getGuardUser()->getId())->limit(1)->fetchOne(); if ($ref) { $comment = Comment::createFromArray(['ticket_id' => $data['ticketId'], 'text' => 'Пользователь @' . $this->getUser()->getGuardUser()->getUsername() . ' отказался от выполнения заявки по причине: ' . $data['reason']]); $ref->delete(); $comment->save(); } return sfView::NONE; }