diff --git a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php index 540c6104b0..126611ef2b 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php @@ -61,6 +61,7 @@ use Alchemy\Phrasea\SearchEngine\SearchEngineResult; use Alchemy\Phrasea\SearchEngine\SearchEngineSuggestion; use Alchemy\Phrasea\Status\StatusStructure; use Alchemy\Phrasea\TaskManager\LiveInformation; +use Alchemy\Phrasea\Utilities\NullableDateTime; use Doctrine\ORM\EntityManager; use Symfony\Component\Form\Form; use Symfony\Component\HttpFoundation\File\UploadedFile; @@ -138,10 +139,10 @@ class V1Controller extends Controller 'pid' => $data['process-id'], 'jobId' => $task->getJobId(), 'period' => $task->getPeriod(), - 'last_exec_time' => $task->getLastExecution() ? $task->getLastExecution()->format(DATE_ATOM) : null, - 'last_execution' => $task->getLastExecution() ? $task->getLastExecution()->format(DATE_ATOM) : null, - 'updated' => $task->getUpdated() ? $task->getUpdated()->format(DATE_ATOM) : null, - 'created' => $task->getCreated() ? $task->getCreated()->format(DATE_ATOM) : null, + 'last_exec_time' => NullableDateTime::format($task->getLastExecution()), + 'last_execution' => NullableDateTime::format($task->getLastExecution()), + 'updated' => NullableDateTime::format($task->getUpdated()), + 'created' => NullableDateTime::format($task->getCreated()), 'auto_start' => $task->getStatus() === Task::STATUS_STARTED, 'crashed' => $task->getCrashed(), ]; @@ -709,9 +710,9 @@ class V1Controller extends Controller 'position' => $user->getActivity() ?: null, 'company' => $user->getCompany() ?: null, 'geoname_id' => $user->getGeonameId() ?: null, - 'last_connection' => $user->getLastConnection() ? $user->getLastConnection()->format(DATE_ATOM) : null, - 'created_on' => $user->getCreated() ? $user->getCreated()->format(DATE_ATOM) : null, - 'updated_on' => $user->getUpdated() ? $user->getUpdated()->format(DATE_ATOM) : null, + 'last_connection' => NullableDateTime::format($user->getLastConnection()), + 'created_on' => NullableDateTime::format($user->getCreated()), + 'updated_on' => NullableDateTime::format($user->getUpdated()), 'locale' => $user->getLocale() ?: null, ]; } @@ -1466,11 +1467,7 @@ class V1Controller extends Controller ]; }, iterator_to_array($basket->getValidation()->getParticipants())); - $expires_on_atom = $basket->getValidation()->getExpires(); - - if ($expires_on_atom instanceof \DateTime) { - $expires_on_atom = $expires_on_atom->format(DATE_ATOM); - } + $expires_on_atom = NullableDateTime::format($basket->getValidation()->getExpires()); $ret = array_merge([ 'validation_users' => $users, diff --git a/lib/Alchemy/Phrasea/Feed/Formatter/AtomFormatter.php b/lib/Alchemy/Phrasea/Feed/Formatter/AtomFormatter.php index be7533249d..5371f97a41 100644 --- a/lib/Alchemy/Phrasea/Feed/Formatter/AtomFormatter.php +++ b/lib/Alchemy/Phrasea/Feed/Formatter/AtomFormatter.php @@ -17,6 +17,7 @@ use Alchemy\Phrasea\Feed\FeedInterface; use Alchemy\Phrasea\Feed\Link\FeedLink; use Alchemy\Phrasea\Feed\Link\LinkGeneratorCollection; use Alchemy\Phrasea\Model\Entities\User; +use Alchemy\Phrasea\Utilities\NullableDateTime; use Symfony\Component\HttpFoundation\Response; class AtomFormatter extends FeedFormatterAbstract implements FeedFormatterInterface @@ -48,8 +49,6 @@ class AtomFormatter extends FeedFormatterAbstract implements FeedFormatterInterf */ public function format(FeedInterface $feed, $page, User $user = null, $generator = 'Phraseanet', Application $app = null) { - $updated_on = $feed->getUpdatedOn(); - $document = new \DOMDocument('1.0', 'UTF-8'); $document->formatOutput = true; $document->standalone = true; @@ -59,8 +58,7 @@ class AtomFormatter extends FeedFormatterAbstract implements FeedFormatterInterf $root->setAttribute('xmlns:media', 'http://search.yahoo.com/mrss/'); $this->addTag($document, $root, 'title', $feed->getTitle()); - if ($updated_on instanceof \DateTime) { - $updated_on = $updated_on->format(DATE_ATOM); + if (null !== $updated_on = NullableDateTime::format($feed->getUpdatedOn())) { $this->addTag($document, $root, 'updated', $updated_on); } diff --git a/lib/Alchemy/Phrasea/Feed/Formatter/CoolirisFormatter.php b/lib/Alchemy/Phrasea/Feed/Formatter/CoolirisFormatter.php index 936a5aba87..a7f81addf9 100644 --- a/lib/Alchemy/Phrasea/Feed/Formatter/CoolirisFormatter.php +++ b/lib/Alchemy/Phrasea/Feed/Formatter/CoolirisFormatter.php @@ -19,6 +19,7 @@ use Alchemy\Phrasea\Model\Entities\FeedEntry; use Alchemy\Phrasea\Model\Entities\FeedItem; use Alchemy\Phrasea\Feed\Link\LinkGeneratorCollection; use Alchemy\Phrasea\Model\Entities\User; +use Alchemy\Phrasea\Utilities\NullableDateTime; use DateTime; use Symfony\Component\HttpFoundation\Response; @@ -52,8 +53,6 @@ class CoolirisFormatter extends FeedFormatterAbstract implements FeedFormatterIn */ public function format(FeedInterface $feed, $page, User $user = null, $generator = 'Phraseanet', Application $app = null) { - $updated_on = $feed->getUpdatedOn(); - $doc = new \DOMDocument('1.0', 'UTF-8'); $doc->formatOutput = true; $doc->standalone = true; @@ -89,8 +88,7 @@ class CoolirisFormatter extends FeedFormatterAbstract implements FeedFormatterIn $this->addTag($doc, $channel, 'managingEditor', $this->managingEditor); if (isset($this->webMaster)) $this->addTag($doc, $channel, 'webMaster', $this->webMaster); - if ($updated_on instanceof DateTime) { - $updated_on = $updated_on->format(DATE_RFC2822); + if (null !== $updated_on = NullableDateTime::format($feed->getUpdatedOn(), DATE_RFC2822)) { $this->addTag($doc, $channel, 'pubDate', $updated_on); } if (isset($this->lastBuildDate) && $this->lastBuildDate instanceof DateTime) { diff --git a/lib/Alchemy/Phrasea/Feed/Formatter/RssFormatter.php b/lib/Alchemy/Phrasea/Feed/Formatter/RssFormatter.php index ec892d2fc3..9e5a923470 100644 --- a/lib/Alchemy/Phrasea/Feed/Formatter/RssFormatter.php +++ b/lib/Alchemy/Phrasea/Feed/Formatter/RssFormatter.php @@ -17,6 +17,7 @@ use Alchemy\Phrasea\Feed\Link\FeedLink; use Alchemy\Phrasea\Feed\Link\LinkGeneratorCollection; use Alchemy\Phrasea\Feed\RSS\FeedRSSImage; use Alchemy\Phrasea\Model\Entities\User; +use Alchemy\Phrasea\Utilities\NullableDateTime; use Symfony\Component\HttpFoundation\Response; use Alchemy\Phrasea\Model\Entities\FeedEntry; use Alchemy\Phrasea\Feed\Link\FeedLinkGenerator; @@ -51,8 +52,6 @@ class RssFormatter extends FeedFormatterAbstract implements FeedFormatterInterfa */ public function format(FeedInterface $feed, $page, User $user = null, $generator = 'Phraseanet', Application $app = null) { - $updated_on = $feed->getUpdatedOn(); - $next = $prev = null; if ($feed->hasPage($page + 1, self::PAGE_SIZE)) { @@ -104,11 +103,10 @@ class RssFormatter extends FeedFormatterAbstract implements FeedFormatterInterfa $this->addTag($doc, $channel, 'managingEditor', $this->managingEditor); if (isset($this->webMaster)) $this->addTag($doc, $channel, 'webMaster', $this->webMaster); - if ($updated_on instanceof \DateTime) { - $updated_on = $updated_on->format(DATE_RFC2822); + if (null !== $updated_on = NullableDateTime::format($feed->getUpdatedOn(), DATE_RFC2822)) { $this->addTag($doc, $channel, 'pubDate', $updated_on); } - if (isset($this->lastBuildDate) && $this->lastBuildDate instanceof DateTime) { + if (isset($this->lastBuildDate) && $this->lastBuildDate instanceof \DateTime) { $last_build = $this->lastBuildDate->format(DATE_RFC2822); $this->addTag($doc, $channel, 'lastBuildDate', $last_build); } diff --git a/lib/Alchemy/Phrasea/Order/Controller/ApiOrderController.php b/lib/Alchemy/Phrasea/Order/Controller/ApiOrderController.php index 06f2ca60a1..f11b3f2202 100644 --- a/lib/Alchemy/Phrasea/Order/Controller/ApiOrderController.php +++ b/lib/Alchemy/Phrasea/Order/Controller/ApiOrderController.php @@ -94,8 +94,8 @@ class ApiOrderController extends BaseOrderController $pager = new Pagerfanta(new DoctrineORMAdapter($builder, false)); $pager->setCurrentPage($page); $pager->setMaxPerPage($perPage); - $paginator = new PagerfantaPaginatorAdapter($pager, $routeGenerator); - $resource->setPaginator($paginator); + + $resource->setPaginator(new PagerfantaPaginatorAdapter($pager, $routeGenerator)); return $this->returnResourceResponse($request, $fractal, $resource); } diff --git a/lib/Alchemy/Phrasea/Utilities/NullableDateTime.php b/lib/Alchemy/Phrasea/Utilities/NullableDateTime.php new file mode 100644 index 0000000000..6f47da81c7 --- /dev/null +++ b/lib/Alchemy/Phrasea/Utilities/NullableDateTime.php @@ -0,0 +1,19 @@ +format($format) : $default; + } +} diff --git a/lib/classes/ACL.php b/lib/classes/ACL.php index 649a781528..f5f62f4cb5 100644 --- a/lib/classes/ACL.php +++ b/lib/classes/ACL.php @@ -26,6 +26,7 @@ use Alchemy\Phrasea\Core\Event\Acl\SysadminChangedEvent; use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\RecordInterface; use Alchemy\Phrasea\Model\RecordReferenceInterface; +use Alchemy\Phrasea\Utilities\NullableDateTime; use Doctrine\DBAL\DBALException; @@ -1706,10 +1707,10 @@ class ACL implements cache_cacheableInterface } $params = [ - ':usr_id' => $this->user->getId() - , ':base_id' => $base_id - , 'limited_from' => ($limit_from ? $limit_from->format(DATE_ISO8601) : null) - , 'limited_to' => ($limit_to ? $limit_to->format(DATE_ISO8601) : null) + ':usr_id' => $this->user->getId(), + ':base_id' => $base_id, + 'limited_from' => NullableDateTime::format($limit_from, DATE_ISO8601), + 'limited_to' => NullableDateTime::format($limit_to, DATE_ISO8601), ]; $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); diff --git a/lib/classes/Bridge/Element.php b/lib/classes/Bridge/Element.php index 4283e7f9eb..5a81808e55 100644 --- a/lib/classes/Bridge/Element.php +++ b/lib/classes/Bridge/Element.php @@ -10,6 +10,7 @@ */ use Alchemy\Phrasea\Application; +use Alchemy\Phrasea\Utilities\NullableDateTime; class Bridge_Element { @@ -383,9 +384,9 @@ class Bridge_Element SET uploaded_on = :uploaded_on, updated_on = :update WHERE id = :id'; $params = [ - ':uploaded_on' => $this->uploaded_on ? $this->uploaded_on->format(DATE_ISO8601) : null - , ':id' => $this->id - , ':update' => $this->updated_on->format(DATE_ISO8601) + ':uploaded_on' => NullableDateTime::format($this->uploaded_on, DATE_ISO8601), + ':id' => $this->id, + ':update' => $this->updated_on->format(DATE_ISO8601), ]; $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); diff --git a/lib/classes/media/subdef.php b/lib/classes/media/subdef.php index 0f167e426e..f37a154df0 100644 --- a/lib/classes/media/subdef.php +++ b/lib/classes/media/subdef.php @@ -11,6 +11,7 @@ use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Http\StaticFile\Symlink\SymLinker; +use Alchemy\Phrasea\Utilities\NullableDateTime; use Guzzle\Http\Url; use MediaAlchemyst\Alchemyst; use MediaVorus\Media\MediaInterface; @@ -206,8 +207,8 @@ SQL; 'physically_present' => $this->is_physically_present, 'is_substituted' => $this->is_substituted, 'subdef_id' => $this->subdef_id, - 'updated_on' => $this->modification_date ? $this->modification_date->format(DATE_ATOM) : '', - 'created_on' => $this->creation_date ? $this->creation_date->format(DATE_ATOM) : '', + 'updated_on' => NullableDateTime::format($this->modification_date), + 'created_on' => NullableDateTime::format($this->creation_date), 'etag' => $this->etag, 'url' => (string)$this->url, ];