Skip to content

Commit

Permalink
Cleaned code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Berthereau authored and Daniel Berthereau committed Jan 9, 2023
1 parent 10cf004 commit 16b370f
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 35 deletions.
5 changes: 2 additions & 3 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* Keeps original names of files and put them in a hierarchical structure.
*
* Copyright Daniel Berthereau 2012-2022
* Copyright Daniel Berthereau 2012-2023
* Copyright BibLibre, 2016
*
* This software is governed by the CeCILL license under French law and abiding
Expand Down Expand Up @@ -46,7 +46,6 @@
use Laminas\EventManager\SharedEventManagerInterface;
use Laminas\View\Renderer\PhpRenderer;
use Omeka\Entity\Media;
use Omeka\Mvc\Controller\Plugin\Messenger;

class Module extends AbstractModule
{
Expand Down Expand Up @@ -229,7 +228,7 @@ public function afterDeleteItem(Event $event): void

protected function addError($msg): void
{
$messenger = new Messenger;
$messenger = $this->getServiceLocator()->get('ControllerPluginManager')->get('messenger');
$messenger->addError($msg);
}

Expand Down
12 changes: 5 additions & 7 deletions data/scripts/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,28 @@

namespace ArchiveRepertory;

use Omeka\Mvc\Controller\Plugin\Messenger;
use Omeka\Stdlib\Message;

/**
* @var Module $this
* @var \Laminas\ServiceManager\ServiceLocatorInterface $serviceLocator
* @var \Laminas\ServiceManager\ServiceLocatorInterface $services
* @var string $oldVersion
* @var string $newVersion
*/
$services = $serviceLocator;

/**
* @var \Omeka\Settings\Settings $settings
* @var \Doctrine\DBAL\Connection $connection
* @var array $config
* @var array $config
* @var \Omeka\Mvc\Controller\Plugin\Api $api
* @var \Omeka\Settings\Settings $settings
* @var \Omeka\Mvc\Controller\Plugin\Messenger $messenger
*/
$settings = $services->get('Omeka\Settings');
$connection = $services->get('Omeka\Connection');
$config = require dirname(__DIR__, 2) . '/config/module.config.php';
$plugins = $services->get('ControllerPluginManager');
$api = $plugins->get('api');
$settings = $services->get('Omeka\Settings');
$messenger = $plugins->get('messenger');

if (version_compare($oldVersion, '3.14.0', '<')) {
$defaultSettings = $config[strtolower(__NAMESPACE__)]['config'];
Expand Down Expand Up @@ -61,7 +60,6 @@
}

if (version_compare($oldVersion, '3.15.14.3', '<')) {
$messenger = new Messenger();
$message = new Message(
'The process is now working with background processes.' // @translate
);
Expand Down
5 changes: 2 additions & 3 deletions src/File/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Omeka\Entity\Media;
use Omeka\Entity\Resource;
use Omeka\File\Exception\RuntimeException;
use Omeka\Mvc\Controller\Plugin\Messenger;
use Omeka\Stdlib\Message;

class FileManager
Expand Down Expand Up @@ -644,7 +643,7 @@ protected function createFolder($path): bool
if ($fileWriter->fileExists($path)) {
if ($fileWriter->is_dir($path)) {
@chmod($path, 0775);
if ($fileWriter->is_writable($path)) {
if ($fileWriter->is_writeable($path)) {
return true;
}
$msg = $this->translate('Error directory non writable: "%s".', $path);
Expand Down Expand Up @@ -740,7 +739,7 @@ protected function getSetting($name)

protected function addError($msg): void
{
$messenger = new Messenger();
$messenger = $this->services->get('ControllerPluginManager')->get('messenger');
$messenger->addError($msg);
}
}
4 changes: 2 additions & 2 deletions src/File/FileWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function is_dir($path): bool
return is_dir((string) $path);
}

public function is_writable($path): bool
public function is_writeable($path): bool
{
return is_writeable((string) $path);
}
Expand Down Expand Up @@ -73,7 +73,7 @@ public function removeDir($path, $evenNonEmpty = false): bool
&& file_exists($path)
&& is_dir($path)
&& is_readable($path)
&& is_writable($path)
&& is_writeable($path)
&& ($evenNonEmpty || count(array_diff(@scandir($path), ['.', '..'])) == 0)
) {
return $this->recursiveRemoveDir($path);
Expand Down
22 changes: 12 additions & 10 deletions src/Form/ConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ class ConfigForm extends Form implements TranslatorAwareInterface

protected $local_storage = '';

public function setLocalStorage($local_storage): void
{
$this->local_storage = $local_storage;
}

public function setSettings($settings): void
{
$this->settings = $settings;
}

public function init(): void
{
$this->add([
Expand Down Expand Up @@ -167,4 +157,16 @@ protected function getRadioForConversion($name, $label)

return $radio;
}

public function setLocalStorage($local_storage): self
{
$this->local_storage = $local_storage;
return $this;
}

public function setSettings($settings): self
{
$this->settings = $settings;
return $this;
}
}
13 changes: 5 additions & 8 deletions src/Service/Form/ConfigFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ class ConfigFormFactory implements FactoryInterface
public function __invoke(ContainerInterface $services, $requestedName, array $options = null)
{
$basePath = $services->get('Config')['file_store']['local']['base_path'] ?: (OMEKA_PATH . '/files');
$settings = $services->get('Omeka\Settings');
$translator = $services->get('MvcTranslator');

$form = new ConfigForm(null, $options);
$form->setLocalStorage($basePath);
$form->setSettings($settings);
$form->setTranslator($translator);

return $form;
$form = new ConfigForm(null, $options ?? []);
return $form
->setLocalStorage($basePath)
->setSettings($services->get('Omeka\Settings'))
->setTranslator($services->get('MvcTranslator'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function testDuplicateNameShouldMoveFileWithAnotherName(): void

protected function getMessengerFirstSuccessMessage()
{
$messenger = new Messenger();
$messenger = $this->getServiceLocator()->get('ControllerPluginManager')->get('messenger');
$messages = $messenger->get();
return $messages[Messenger::SUCCESS][0];
}
Expand Down
2 changes: 1 addition & 1 deletion test/ArchiveRepertoryTest/MockFileWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function fileExists($path)
return in_array($path, $this->files);
}

public function is_writable($path)
public function is_writeable($path)
{
return true;
}
Expand Down

0 comments on commit 16b370f

Please sign in to comment.