Exemplo n.º 1
0
 public function testParamsReturnedInSolrResponse()
 {
     $q = [];
     $search = new Search();
     $solrResponse = $search->query($q);
     $this->assertTrue(isset($solrResponse->responseHeader), 'Solr response is missing responseHeader');
     $this->assertTrue(isset($solrResponse->responseHeader->params), 'Solr response is missing params in responseHeader');
 }
 /**
  * Provides ticket searching
  */
 public function index()
 {
     $format = isset($_GET['resultFormat']) ? trim($_GET['resultFormat']) : '';
     if ($format == 'raw' && $this->template->outputFormat == 'html' && Person::isAllowed('tickets', 'print')) {
         $this->template->setFilename('print');
     } else {
         $this->template->setFilename('search');
     }
     $search = new Search();
     $solrObject = $search->query($_GET, $format == 'raw' ? true : false);
     $this->template->blocks['left'][] = new Block('tickets/searchForm.inc', array('solrObject' => $solrObject));
     $this->template->blocks['right'][] = new Block('tickets/searchParameters.inc', array('solrObject' => $solrObject));
     $resultBlock = $format == 'map' ? 'searchResultsMap.inc' : 'searchResults.inc';
     $this->template->blocks['right'][] = new Block("tickets/{$resultBlock}", array('solrObject' => $solrObject));
 }
Exemplo n.º 3
0
 /**
  * Does all the database work for TicketController::add
  *
  * Saves the ticket, the issue, and creates history entries
  * for the open and assignment actions.
  *
  * This function calls save() as needed.  After using this function,
  * there's no need to make an additional save() call.
  *
  * @param array $post
  */
 public function handleAdd($post)
 {
     $zend_db = Database::getConnection();
     $zend_db->getDriver()->getConnection()->beginTransaction();
     try {
         $this->handleUpdate($post);
         // We must add an issue to the ticket for validation to pass
         $issue = new Issue();
         $issue->handleUpdate($post);
         $this->issues = array($issue);
         if (!$this->getEnteredByPerson_id() && $issue->getReportedByPerson_id()) {
             $this->setEnteredByPerson_id($issue->getReportedByPerson_id());
         }
         $this->save();
         $issue->setTicket($this);
         $issue->save();
         // Create the entry in the history log
         $history = new TicketHistory();
         $history->setTicket($this);
         $history->setAction(new Action('open'));
         if ($this->getEnteredByPerson_id()) {
             $history->setEnteredByPerson_id($this->getEnteredByPerson_id());
         }
         $history->save();
         $history = new TicketHistory();
         $history->setTicket($this);
         $history->setAction(new Action('assignment'));
         $history->setActionPerson_id($this->getAssignedPerson_id());
         if (!empty($post['notes'])) {
             $history->setNotes($post['notes']);
         }
         if ($this->getEnteredByPerson_id()) {
             $history->setEnteredByPerson_id($this->getEnteredByPerson_id());
         }
         $history->save();
         $this->getCategory()->onTicketAdd($this);
     } catch (\Exception $e) {
         $zend_db->getDriver()->getConnection()->rollback();
         $search = new Search();
         $search->delete($this);
         $search->solrClient->commit();
         throw $e;
     }
     $zend_db->getDriver()->getConnection()->commit();
     $history->sendNotification($this);
 }
Exemplo n.º 4
0
<?php

/**
 * @copyright 2012-2014 City of Bloomington, Indiana
 * @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
 * @author Cliff Ingham <*****@*****.**>
 */
use Application\Models\Search;
use Application\Models\Ticket;
use Blossom\Classes\Database;
include '../../configuration.inc';
$search = new Search();
$search->solrClient->deleteByQuery('*:*');
$search->solrClient->commit();
$sql = 'select * from tickets';
$zend_db = Database::getConnection();
$result = $zend_db->query($sql)->execute();
$count = count($result);
foreach ($result as $c => $row) {
    $ticket = new Ticket($row);
    $search->add($ticket);
    echo "{$c}/{$count}: {$ticket->getId()}\n";
}
echo "Committing\n";
$search->solrClient->commit();
echo "Optimizing\n";
$search->solrClient->optimize();
echo "Done\n";
Exemplo n.º 5
0
 /**
  * Transfers all data from a person, then deletes that person
  *
  * This person will end up containing all information from both people
  * I took care to make sure to update the search index as well
  * as the database.
  *
  * @param Person $person
  */
 public function mergeFrom(Person $person)
 {
     if ($this->getId() && $person->getId()) {
         if ($this->getId() == $person->getId()) {
             // can not merge same person throw exception
             throw new \Exception('mergerNotAllowed');
         }
         $zend_db = Database::getConnection();
         // Look up all the tickets we're about to modify
         // We need to remember them so we can update the search
         // index after we've updated the database
         $id = (int) $person->getId();
         $sql = "select distinct t.id from tickets t\n\t\t\t\t\tleft join ticketHistory th on t.id=th.ticket_id\n\t\t\t\t\tleft join issues         i on t.id= i.ticket_id\n\t\t\t\t\tleft join issueHistory  ih on i.id=ih.issue_id\n\t\t\t\t\tleft join media          m on i.id= m.issue_id\n\t\t\t\t\tleft join responses      r on i.id= r.issue_id\n\t\t\t\t\twhere ( t.enteredByPerson_id={$id} or t.assignedPerson_id={$id} or t.referredPerson_id={$id})\n\t\t\t\t\t   or (th.enteredByPerson_id={$id} or th.actionPerson_id={$id})\n\t\t\t\t\t   or ( i.enteredByPerson_id={$id} or i.reportedByPerson_id={$id})\n\t\t\t\t\t   or (ih.enteredByPerson_id={$id} or ih.actionPerson_id={$id})\n\t\t\t\t\t   or m.person_id={$id} or r.person_id={$id}";
         $result = $zend_db->query($sql)->execute();
         $ticketIds = [];
         foreach ($result as $row) {
             $ticketIds[] = $row['id'];
         }
         $zend_db->getDriver()->getConnection()->beginTransaction();
         try {
             // These are all the database fields that hit the Solr index
             $zend_db->query('update responses     set           person_id=? where           person_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update media         set           person_id=? where           person_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update issueHistory  set  enteredByPerson_id=? where  enteredByPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update issueHistory  set     actionPerson_id=? where     actionPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update issues        set  enteredByPerson_id=? where  enteredByPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update issues        set reportedByPerson_id=? where reportedByPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update ticketHistory set  enteredByPerson_id=? where  enteredByPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update ticketHistory set     actionPerson_id=? where     actionPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update tickets       set  enteredByPerson_id=? where  enteredByPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update tickets       set   assignedPerson_id=? where   assignedPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update tickets       set   referredPerson_id=? where   referredPerson_id=?')->execute([$this->getId(), $person->getId()]);
             // Fields that don't hit the Solr index
             $zend_db->query('update clients         set contactPerson_id=? where contactPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update departments     set defaultPerson_id=? where defaultPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update peopleAddresses set        person_id=? where        person_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update peoplePhones    set        person_id=? where        person_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update peopleEmails    set        person_id=? where        person_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('delete from people where id=?')->execute([$person->getId()]);
         } catch (Exception $e) {
             $zend_db->getDriver()->getConnection()->rollback();
             throw $e;
         }
         $zend_db->getDriver()->getConnection()->commit();
         foreach ($ticketIds as $id) {
             $search = new Search();
             $ticket = new Ticket($id);
             $search->add($ticket);
         }
     }
 }