if (is_array($parameters)) {
$this->parameterContainer->setFromArray($parameters);
}
if ($this->parameterContainer->count() > 0) {
$this->bindParametersFromContainer();
}
/** END Standard ParameterContainer Merging Block */
if ($this->profiler) {
$this->profiler->profilerStart($this);
}
try {
$this->resource->execute();
} catch (\PDOException $e) {
if ($this->profiler) {
$this->profiler->profilerFinish();
}
throw new Exception\InvalidQueryException(
'Statement could not be executed (' . implode(' - ', $this->resource->errorInfo()) . ')',
null,
$e
);
}
if ($this->profiler) {
$this->profiler->profilerFinish();
}
$result = $this->driver->createResult($this->resource, $this);
return $result;
}
/**
* Bind parameters from container
*/
protected function bindParametersFromContainer()
{
if ($this->parametersBound) {
} else {
$this->parameterContainer = new ParameterContainer();
}
}
if (is_array($parameters)) {
$this->parameterContainer->setFromArray($parameters);
}
if ($this->parameterContainer->count() > 0) {
$this->bindParametersFromContainer();
}
/** END Standard ParameterContainer Merging Block */
if ($this->profiler) {
$this->profiler->profilerStart($this);
}
try {
$this->resource->execute();
} catch (\PDOException $e) {
if ($this->profiler) {
$this->profiler->profilerFinish();
}
throw new Exception\InvalidQueryException(
'Statement could not be executed (' . implode(' - ', $this->resource->errorInfo()) . ')',
null,
$e
);
}
if ($this->profiler) {
$this->profiler->profilerFinish();
}
$result = $this->driver->createResult($this->resource, $this);
return $result;
}
/**
} else {
$this->parameterContainer = new ParameterContainer();
}
}
if (is_array($parameters)) {
$this->parameterContainer->setFromArray($parameters);
}
if ($this->parameterContainer->count() > 0) {
$this->bindParametersFromContainer();
}
/** END Standard ParameterContainer Merging Block */
if ($this->profiler) {
$this->profiler->profilerStart($this);
}
try {
$this->resource->execute();
} catch (\PDOException $e) {
if ($this->profiler) {
$this->profiler->profilerFinish();
}
throw new Exception\InvalidQueryException(
'Statement could not be executed (' . implode(' - ', $this->resource->errorInfo()) . ')',
null,
$e
);
}
if ($this->profiler) {
$this->profiler->profilerFinish();
}
$result = $this->driver->createResult($this->resource, $this);
return $result;
}
/**
if ($this->rowExistsInDatabase()) {
// UPDATE
$data = $this->data;
$where = [];
$isPkModified = false;
// primary key is always an array even if its a single column
foreach ($this->primaryKeyColumn as $pkColumn) {
$where[$pkColumn] = $this->primaryKeyData[$pkColumn];
if ($data[$pkColumn] == $this->primaryKeyData[$pkColumn]) {
unset($data[$pkColumn]);
} else {
$isPkModified = true;
}
}
$statement = $this->sql->prepareStatementForSqlObject($this->sql->update()->set($data)->where($where));
$result = $statement->execute();
$rowsAffected = $result->getAffectedRows();
unset($statement, $result); // cleanup
// If one or more primary keys are modified, we update the where clause
if ($isPkModified) {
foreach ($this->primaryKeyColumn as $pkColumn) {
if ($data[$pkColumn] != $this->primaryKeyData[$pkColumn]) {
$where[$pkColumn] = $data[$pkColumn];
}
}
}
} else {
// INSERT
$insert = $this->sql->insert();
$insert->values($this->data);
$statement = $this->sql->prepareStatementForSqlObject($insert);
$result = $statement->execute();
if (($primaryKeyValue = $result->getGeneratedValue()) && count($this->primaryKeyColumn) == 1) {
// We need to make sure the search object is a string before unserializing:
$this->normalizeSearchObject();
$result = unserialize($this->search_object);
if (!($result instanceof \VuFind\Search\Minified)) {
throw new \Exception('Problem decoding saved search');
}
return $result;
}
/**
* Save
*
* @return int
*/
public function save()
{
// We can't save if the search object is a resource; make sure it's a
// string first:
$this->normalizeSearchObject();
return parent::save();
}
/**
* Set last executed time for scheduled alert.
*
* @param string $time Time.
*
* @return mixed
*/
public function setLastExecuted($time)
{
$this->last_notification_sent = $time;
return $this->save();
}
/**
* Set schedule for scheduled alert.
*
* @param int $schedule Schedule.
* @param string $url Site base URL
// Update the new search from the existing one
$newSearch->updateSaveStatus($oldSearch);
return $oldSearch;
}
}
// If we got this far, we didn't find a saved duplicate, so we should
// save the new search:
$this->insert(['created' => date('Y-m-d H:i:s'), 'checksum' => $checksum]);
$row = $this->getRowById($this->getLastInsertValue());
// Chicken and egg... We didn't know the id before insert
$newSearch->updateSaveStatus($row);
// Don't set session ID until this stage, because we don't want to risk
// ever having a row that's associated with a session but which has no
// search object data attached to it; this could cause problems!
$row->session_id = $sessionId;
$row->search_object = serialize(new minSO($newSearch));
$row->save();
return $row;
}
/**
* Update the select statement to find records to delete.
*
* @param Select $select Select clause
* @param int $daysOld Age in days of an "expired" record.
*
* @return void
*/
protected function expirationCallback($select, $daysOld)
{
$expireDate = date('Y-m-d H:i:s', time() - $daysOld * 24 * 60 * 60);
$select->where->lessThan('created', $expireDate)->equalTo('saved', 0);
}
}
return $searchTable->getOwnedRowById($searchId, $sessId, $userId);
}
/**
* Save a search to the history in the database.
*
* @param \VuFind\Search\Base\Results $results Search results
*
* @return void
*/
protected function saveSearchToHistory($results)
{
$user = $this->getUser();
$sessId = $this->serviceLocator->get(SessionManager::class)->getId();
$history = $this->getTable('Search');
$history->saveSearch(
$this->getResultsManager(),
$results,
$sessId,
$user->id ?? null
);
}
/**
* Either assign the requested search object to the view or display a flash
* message indicating why the operation failed.
*
* @param string $searchId ID value of a saved advanced search.
*
* @return bool|object Restored search object if found, false otherwise.
*/
protected function restoreAdvancedSearch($searchId)
{
// Look up search in database and fail if it is not found:
$search = $this->retrieveSearchSecurely($searchId);
if (empty($search)) {
$this->flashMessenger()->addMessage('advSearchError_notFound', 'error');
return false;
}
$view->params = $results->getParams();
// If we received an EmptySet back, that indicates that the real search
// failed due to some kind of syntax error, and we should display a
// warning to the user; otherwise, we should proceed with normal post-search
// processing.
if ($results instanceof \VuFind\Search\EmptySet\Results) {
$view->parseError = true;
} else {
// If a "jumpto" parameter is set, deal with that now:
if ($jump = $this->processJumpTo($results)) {
return $jump;
}
// Remember the current URL as the last search.
$this->rememberSearch($results);
// Add to search history:
if ($this->saveToHistory) {
$this->saveSearchToHistory($results);
}
// Set up results scroller:
if ($this->resultScrollerActive()) {
$this->resultScroller()->init($results);
}
foreach ($results->getErrors() as $error) {
$this->flashMessenger()->addErrorMessage($error);
}
}
// Special case: If we're in RSS view, we need to render differently:
if (isset($view->params) && $view->params->getView() == 'rss') {
$response = $this->getResponse();
$response->getHeaders()->addHeaderLine('Content-type', 'text/xml');
$feed = $this->getViewRenderer()->plugin('resultfeed');
$response->setContent($feed($view->results)->export('rss'));
return $response;
}
throw new \Exception('Unrecoverable deep paging error.');
}
$request['page'] = $page;
$this->flashMessenger()->addErrorMessage(
[
'msg' => 'deep_paging_failure',
'tokens' => ['%%page%%' => $page],
]
);
return $this->redirect()->toUrl('?' . http_build_query($request));
}
/**
* Send search results to results view
*
* @return \Laminas\View\Model\ViewModel
*/
public function resultsAction()
{
return $this->getSearchResultsView();
}
/**
* Perform a search and send results to a results view
*
* @param callable $setupCallback Optional setup callback that overrides the
* default one
*
* @return \Laminas\View\Model\ViewModel
*/
protected function getSearchResultsView($setupCallback = null)
{
$view = $this->createViewModel();
// Handle saved search requests:
$savedId = $this->params()->fromQuery('saved', false);
if ($savedId !== false) {
return $this->redirectToSavedSearch($savedId);
}
*/
public function resultsAction()
{
// Special case -- redirect tag searches.
$tag = $this->params()->fromQuery('tag');
if (!empty($tag)) {
$query = $this->getRequest()->getQuery();
$query->set('lookfor', $tag);
$query->set('type', 'tag');
}
if ($this->params()->fromQuery('type') == 'tag') {
// Because we're coming in from a search, we want to do a fuzzy
// tag search, not an exact search like we would when linking to a
// specific tag name.
$query = $this->getRequest()->getQuery()->set('fuzzy', 'true');
return $this->forwardTo('Tag', 'Home');
}
// Default case -- standard behavior.
return parent::resultsAction();
}
/**
* Handle OpenSearch.
*
* @return \Laminas\Http\Response
*/
public function opensearchAction()
{
switch ($this->params()->fromQuery('method')) {
case 'describe':
$config = $this->getConfig();
$xml = $this->getViewRenderer()->render(
'search/opensearch-describe.phtml',
['site' => $config->Site]
);
break;
default:
$xml = $this->getViewRenderer()->render('search/opensearch-error.phtml');
break;
*/
public function onDispatch(MvcEvent $e)
{
$routeMatch = $e->getRouteMatch();
if (! $routeMatch) {
/**
* @todo Determine requirements for when route match is missing.
* Potentially allow pulling directly from request metadata?
*/
throw new Exception\DomainException('Missing route matches; unsure how to retrieve action');
}
$action = $routeMatch->getParam('action', 'not-found');
$method = static::getMethodFromAction($action);
if (! method_exists($this, $method)) {
$method = 'notFoundAction';
}
$actionResponse = $this->$method();
$e->setResult($actionResponse);
return $actionResponse;
}
}
}
if ($this->sharedManager) {
foreach ($this->sharedManager->getListeners($this->identifiers, $name) as $priority => $listeners) {
$listOfListenersByPriority[$priority][] = $listeners;
}
}
// Sort by priority in reverse order
krsort($listOfListenersByPriority);
// Initial value of stop propagation flag should be false
$event->stopPropagation(false);
// Execute listeners
$responses = new ResponseCollection();
foreach ($listOfListenersByPriority as $listOfListeners) {
foreach ($listOfListeners as $listeners) {
foreach ($listeners as $listener) {
$response = $listener($event);
$responses->push($response);
// If the event was asked to stop propagating, do so
if ($event->propagationIsStopped()) {
$responses->setStopped(true);
return $responses;
}
// If the result causes our validation callback to return true,
// stop propagation
if ($callback && $callback($response)) {
$responses->setStopped(true);
return $responses;
}
}
}
}
return $responses;
}
$event->setParams($argv);
}
return $this->triggerListeners($event, $callback);
}
/**
* @inheritDoc
*/
public function triggerEvent(EventInterface $event)
{
return $this->triggerListeners($event);
}
/**
* @inheritDoc
*/
public function triggerEventUntil(callable $callback, EventInterface $event)
{
return $this->triggerListeners($event, $callback);
}
/**
* @inheritDoc
*/
public function attach($eventName, callable $listener, $priority = 1)
{
if (! is_string($eventName)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects a string for the event; received %s',
__METHOD__,
(is_object($eventName) ? get_class($eventName) : gettype($eventName))
));
}
$this->events[$eventName][(int) $priority][0][] = $listener;
return $listener;
}
/**
* @events dispatch.pre, dispatch.post
* @param Request $request
* @param null|Response $response
* @return Response|mixed
*/
public function dispatch(Request $request, Response $response = null)
{
$this->request = $request;
if (! $response) {
$response = new HttpResponse();
}
$this->response = $response;
$e = $this->getEvent();
$e->setName(MvcEvent::EVENT_DISPATCH);
$e->setRequest($request);
$e->setResponse($response);
$e->setTarget($this);
$result = $this->getEventManager()->triggerEventUntil(function ($test) {
return ($test instanceof Response);
}, $e);
if ($result->stopped()) {
return $result->last();
}
return $e->getResult();
}
/**
* Get request object
*
* @return Request
*/
public function getRequest()
{
if (! $this->request) {
$this->request = new HttpRequest();
}
);
return $this->complete($return, $e);
} catch (\Throwable $exception) {
$return = $this->marshalBadControllerEvent($controllerName, $e, $application, $exception);
return $this->complete($return, $e);
} catch (\Exception $exception) { // @TODO clean up once PHP 7 requirement is enforced
$return = $this->marshalBadControllerEvent($controllerName, $e, $application, $exception);
return $this->complete($return, $e);
}
if ($controller instanceof InjectApplicationEventInterface) {
$controller->setEvent($e);
}
$request = $e->getRequest();
$response = $application->getResponse();
$caughtException = null;
try {
$return = $controller->dispatch($request, $response);
} catch (\Throwable $ex) {
$caughtException = $ex;
} catch (\Exception $ex) { // @TODO clean up once PHP 7 requirement is enforced
$caughtException = $ex;
}
if ($caughtException !== null) {
$e->setName(MvcEvent::EVENT_DISPATCH_ERROR);
$e->setError($application::ERROR_EXCEPTION);
$e->setController($controllerName);
$e->setControllerClass(get_class($controller));
$e->setParam('exception', $caughtException);
$return = $application->getEventManager()->triggerEvent($e)->last();
if (! $return) {
$return = $e->getResult();
}
}
return $this->complete($return, $e);
}
if ($this->sharedManager) {
foreach ($this->sharedManager->getListeners($this->identifiers, $name) as $priority => $listeners) {
$listOfListenersByPriority[$priority][] = $listeners;
}
}
// Sort by priority in reverse order
krsort($listOfListenersByPriority);
// Initial value of stop propagation flag should be false
$event->stopPropagation(false);
// Execute listeners
$responses = new ResponseCollection();
foreach ($listOfListenersByPriority as $listOfListeners) {
foreach ($listOfListeners as $listeners) {
foreach ($listeners as $listener) {
$response = $listener($event);
$responses->push($response);
// If the event was asked to stop propagating, do so
if ($event->propagationIsStopped()) {
$responses->setStopped(true);
return $responses;
}
// If the result causes our validation callback to return true,
// stop propagation
if ($callback && $callback($response)) {
$responses->setStopped(true);
return $responses;
}
}
}
}
return $responses;
}
$event->setParams($argv);
}
return $this->triggerListeners($event, $callback);
}
/**
* @inheritDoc
*/
public function triggerEvent(EventInterface $event)
{
return $this->triggerListeners($event);
}
/**
* @inheritDoc
*/
public function triggerEventUntil(callable $callback, EventInterface $event)
{
return $this->triggerListeners($event, $callback);
}
/**
* @inheritDoc
*/
public function attach($eventName, callable $listener, $priority = 1)
{
if (! is_string($eventName)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects a string for the event; received %s',
__METHOD__,
(is_object($eventName) ? get_class($eventName) : gettype($eventName))
));
}
$this->events[$eventName][(int) $priority][0][] = $listener;
return $listener;
}
/**
$response = $result->last();
if ($response instanceof ResponseInterface) {
$event->setName(MvcEvent::EVENT_FINISH);
$event->setTarget($this);
$event->setResponse($response);
$event->stopPropagation(false); // Clear before triggering
$events->triggerEvent($event);
$this->response = $response;
return $this;
}
}
if ($event->getError()) {
return $this->completeRequest($event);
}
// Trigger dispatch event
$event->setName(MvcEvent::EVENT_DISPATCH);
$event->stopPropagation(false); // Clear before triggering
$result = $events->triggerEventUntil($shortCircuit, $event);
// Complete response
$response = $result->last();
if ($response instanceof ResponseInterface) {
$event->setName(MvcEvent::EVENT_FINISH);
$event->setTarget($this);
$event->setResponse($response);
$event->stopPropagation(false); // Clear before triggering
$events->triggerEvent($event);
$this->response = $response;
return $this;
}
$response = $this->response;
$event->setResponse($response);
return $this->completeRequest($event);
}
/**
* Complete the request
$pathParts[] = APPLICATION_PATH . '/vendor';
$pathParts[] = get_include_path();
set_include_path(implode(PATH_SEPARATOR, $pathParts));
// Composer autoloading
if (file_exists('vendor/autoload.php')) {
$loader = include 'vendor/autoload.php';
}
if (!class_exists('Laminas\Loader\AutoloaderFactory')) {
throw new RuntimeException('Unable to load Laminas autoloader.');
}
// Run the application!
$app = Laminas\Mvc\Application::init(require 'config/application.config.php');
if (PHP_SAPI === 'cli') {
return $app->getServiceManager()
->get(\VuFindConsole\ConsoleRunner::class)->run();
} else {
$app->run();
}