Skip to content

Commit

Permalink
Merge pull request #3 from Daniel-KM/upgrade/v3
Browse files Browse the repository at this point in the history
Upgrade/v3
  • Loading branch information
symac authored Nov 27, 2020
2 parents e42c481 + 3a41abe commit d11d4bc
Show file tree
Hide file tree
Showing 9 changed files with 1,234 additions and 37 deletions.
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
/asset/vendor
/build
/vendor
/language/debug.po
/language/debug.mo
/language/chef.po
/language/chef.mo
/node_modules
/vendor
.sass-cache/
.php_cs.cache
.bundle
.DS_Store
.php_cs.cache
composer.phar
debug.log
674 changes: 674 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

517 changes: 517 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions Module.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php
<?php declare(strict_types=1);

namespace ExtractOcr;

use ExtractOcr\Form\ConfigForm;
use ExtractOcr\Job\ExtractOcr;
use Laminas\EventManager\Event;
use Laminas\EventManager\SharedEventManagerInterface;
use Laminas\Mvc\Controller\AbstractController;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\View\Renderer\PhpRenderer;
use Omeka\Module\AbstractModule;
use Omeka\Module\Exception\ModuleCannotInstallException;
use Omeka\Settings\SettingsInterface;
use Omeka\Stdlib\Message;
use Zend\EventManager\Event;
use Zend\EventManager\SharedEventManagerInterface;
use Zend\Mvc\Controller\AbstractController;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\View\Renderer\PhpRenderer;

class Module extends AbstractModule
{
Expand All @@ -21,7 +21,7 @@ public function getConfig()
return include __DIR__ . '/config/module.config.php';
}

public function install(ServiceLocatorInterface $services)
public function install(ServiceLocatorInterface $services): void
{
$t = $services->get('MvcTranslator');

Expand All @@ -34,7 +34,7 @@ public function install(ServiceLocatorInterface $services)
}

$basePath = $services->get('Config')['file_store']['local']['base_path'] ?: (OMEKA_PATH . '/files');
if (!$this->checkDestinationDir($basePath . '/temp')) {
if (!$this->checkDir($basePath . '/temp')) {
throw new ModuleCannotInstallException(
$t->translate('The temporary directory "files/temp" is not writeable. Fix rights or create it manually.') //@translate
);
Expand All @@ -61,7 +61,7 @@ public function install(ServiceLocatorInterface $services)
$this->allowXML($services->get('Omeka\Settings'));
}

public function uninstall(ServiceLocatorInterface $services)
public function uninstall(ServiceLocatorInterface $services): void
{
$settings = $services->get('Omeka\Settings');
$config = require __DIR__ . '/config/module.config.php';
Expand All @@ -76,7 +76,7 @@ public function uninstall(ServiceLocatorInterface $services)
*
* @param SharedEventManagerInterface $sharedEventManager
*/
public function attachListeners(SharedEventManagerInterface $sharedEventManager)
public function attachListeners(SharedEventManagerInterface $sharedEventManager): void
{
$sharedEventManager->attach(
\Omeka\Api\Adapter\ItemAdapter::class,
Expand All @@ -95,7 +95,7 @@ public function attachListeners(SharedEventManagerInterface $sharedEventManager)
*
* @param SettingsInterface
*/
protected function allowXML(SettingsInterface $settings)
protected function allowXML(SettingsInterface $settings): void
{
$extensionWhitelist = $settings->get('extension_whitelist', []);
$xmlExtensions = [
Expand Down Expand Up @@ -197,7 +197,7 @@ public function handleConfigForm(AbstractController $controller)
*
* @param Event $event
*/
public function extractOcr(Event $event)
public function extractOcr(Event $event): void
{
$response = $event->getParams()['response'];
/** @var \Omeka\Entity\Item $item */
Expand Down Expand Up @@ -295,10 +295,10 @@ protected function getBaseUri()
* @param string $dirPath
* @return bool
*/
protected function checkDestinationDir($dirPath)
protected function checkDir($dirPath)
{
if (!file_exists($dirPath)) {
if (!is_writeable($this->basePath)) {
if (!is_writeable(basename($dirPath))) {
return false;
}
@mkdir($dirPath, 0755, true);
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ Optional modules
- [IIIF-Search](https://github.com/bubdxm/Omeka-S-module-IiifSearch): Module
for Omeka S that adds IIIF Search Api for fulltext searching on universal
viewer.
- [Universal Viewer](https://github.com/Daniel-KM/Omeka-S-module-UniversalViewer):
- [Universal Viewer](https://gitlab.com/Daniel-KM/Omeka-S-module-UniversalViewer):
Module for Omeka S that includes UniversalViewer, a unified online player for
any file. It can display books, images, maps, audio, movies, pdf, 3D views,
and anything else as long as the appropriate extensions are installed.
Or any other IIIF viewers, like [Mirador](https://github.com/Daniel-KM/Omeka-S-module-Mirador).
Or any other IIIF viewers, like [Mirador](https://gitlab.com/Daniel-KM/Omeka-S-module-Mirador).


Troubleshooting
Expand Down Expand Up @@ -99,4 +99,4 @@ Copyright
---------

* Copyright Syvain Machefert, Université Bordeaux 3 (see [symac](https://github.com/symac))
* Copyright Daniel Berthereau, 2012-2019 (see [Daniel-KM](https://github.com/Daniel-KM) on GitHub)
* Copyright Daniel Berthereau, 2020 (see [Daniel-KM](https://gitlab.com/Daniel-KM) on GitLab)
2 changes: 1 addition & 1 deletion config/module.config.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace ExtractOcr;

Expand Down
4 changes: 2 additions & 2 deletions config/module.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ author = "bubdxm, completed by Daniel Berthereau"
author_link = "https://github.com/symac"
module_link = "http://github.com/bubdxm/Omeka-S-module-ExtractOcr"
configurable = true
version = "2.0.2"
omeka_version_constraint = "^2.1.0"
version = "3.3.2"
omeka_version_constraint = "^3.0.0"
10 changes: 5 additions & 5 deletions src/Form/ConfigForm.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
<?php declare(strict_types=1);
namespace ExtractOcr\Form;

use Laminas\Form\Element;
use Laminas\Form\Fieldset;
use Laminas\Form\Form;
use Omeka\Form\Element\PropertySelect;
use Zend\Form\Element;
use Zend\Form\Fieldset;
use Zend\Form\Form;

class ConfigForm extends Form
{
Expand All @@ -13,7 +13,7 @@ class ConfigForm extends Form
*/
protected $connection;

public function init()
public function init(): void
{
$this
->add([
Expand Down
20 changes: 10 additions & 10 deletions src/Job/ExtractOcr.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
<?php declare(strict_types=1);
namespace ExtractOcr\Job;

use Omeka\Api\Representation\AbstractResourceEntityRepresentation;
use Omeka\Api\Representation\MediaRepresentation;
use Omeka\File\TempFile;
use Omeka\Job\AbstractJob;
use Omeka\Stdlib\Message;
use Omeka\Api\Representation\AbstractResourceEntityRepresentation;

class ExtractOcr extends AbstractJob
{
Expand All @@ -17,7 +17,7 @@ class ExtractOcr extends AbstractJob
const SQL_LIMIT = 25;

/**
* @var \Zend\Log\Logger
* @var \Laminas\Log\Logger
*/
protected $logger;

Expand Down Expand Up @@ -78,7 +78,7 @@ class ExtractOcr extends AbstractJob
/**
* @brief Attach attracted ocr data from pdf with item
*/
public function perform()
public function perform(): void
{
$services = $this->getServiceLocator();
$this->logger = $services->get('Omeka\Logger');
Expand All @@ -87,7 +87,7 @@ public function perform()
$this->cli = $services->get('Omeka\Cli');
$this->baseUri = $this->getArg('baseUri');
$this->basePath = $services->get('Config')['file_store']['local']['base_path'] ?: (OMEKA_PATH . '/files');
if (!$this->checkDestinationDir($this->basePath . '/temp')) {
if (!$this->checkDir($this->basePath . '/temp')) {
$this->logger->err(new Message(
'The temporary directory "files/temp" is not writeable. Fix rights or create it manually.' // @translate
));
Expand Down Expand Up @@ -386,13 +386,13 @@ protected function pdfToText($pdfFilepath)
*
* @param AbstractResourceEntityRepresentation $resource
*/
protected function storeContentInProperty(AbstractResourceEntityRepresentation $resource)
protected function storeContentInProperty(AbstractResourceEntityRepresentation $resource): void
{
if (empty($this->contentValue)) {
return;
}

foreach($resource->value($this->property->term(), ['all' => true, 'default' => []]) as $v) {
foreach ($resource->value($this->property->term(), ['all' => true]) as $v) {
if ($v->value() === $this->contentValue['@value']) {
return;
}
Expand All @@ -416,7 +416,7 @@ protected function storeContentInProperty(AbstractResourceEntityRepresentation $
*
* @param MediaRepresentation $media
*/
protected function reorderMedias(MediaRepresentation $media)
protected function reorderMedias(MediaRepresentation $media): void
{
// Note: the position is not available in representation.

Expand Down Expand Up @@ -458,7 +458,7 @@ protected function makeTempFileDownloadable(TempFile $tempFile, $base = '')
{
$baseDestination = '/temp';
$destinationDir = $this->basePath . $baseDestination . $base;
if (!$this->checkDestinationDir($destinationDir)) {
if (!$this->checkDir($destinationDir)) {
return null;
}

Expand Down Expand Up @@ -498,7 +498,7 @@ protected function makeTempFileDownloadable(TempFile $tempFile, $base = '')
* @param string $dirPath
* @return bool
*/
protected function checkDestinationDir($dirPath)
protected function checkDir($dirPath)
{
if (!file_exists($dirPath)) {
if (!is_writeable($this->basePath)) {
Expand Down

0 comments on commit d11d4bc

Please sign in to comment.