diff --git a/src/Generic/AbstractModule.php b/src/Generic/AbstractModule.php index 4bbc939..414d2d4 100644 --- a/src/Generic/AbstractModule.php +++ b/src/Generic/AbstractModule.php @@ -62,7 +62,9 @@ public function install(ServiceLocatorInterface $serviceLocator) $this->preInstall(); $this->checkDependency(); $this->checkDependencies(); + $this->checkAllResourcesToInstall(); $this->execSqlFromFile($this->modulePath() . '/data/install/schema.sql'); + $this->installAllResources(); $this->manageConfig('install'); $this->manageMainSettings('install'); $this->manageSiteSettings('install'); @@ -92,6 +94,48 @@ public function upgrade($oldVersion, $newVersion, ServiceLocatorInterface $servi } } + /** + * @throws \Omeka\Module\Exception\ModuleCannotInstallException + */ + public function checkAllResourcesToInstall() + { + if (!class_exists(\Generic\InstallResources::class)) { + if (file_exists(dirname(dirname(dirname(__DIR__))) . '/Generic/InstallResources.php')) { + require_once dirname(dirname(dirname(__DIR__))) . '/Generic/InstallResources.php'; + } elseif (file_exists(__DIR__ . '/InstallResources.php')) { + require_once __DIR__ . '/InstallResources.php'; + } else { + // Nothing to install. + return true; + } + } + + $services = $this->getServiceLocator(); + $installResources = new \Generic\InstallResources($services); + $installResources->checkAllResources(static::NAMESPACE); + } + + /** + * @throws \Omeka\Module\Exception\ModuleCannotInstallException + */ + public function installAllResources() + { + if (!class_exists(\Generic\InstallResources::class)) { + if (file_exists(dirname(dirname(dirname(__DIR__))) . '/Generic/InstallResources.php')) { + require_once dirname(dirname(dirname(__DIR__))) . '/Generic/InstallResources.php'; + } elseif (file_exists(__DIR__ . '/InstallResources.php')) { + require_once __DIR__ . '/InstallResources.php'; + } else { + // Nothing to install. + return true; + } + } + + $services = $this->getServiceLocator(); + $installResources = new \Generic\InstallResources($services); + $installResources->createAllResources(static::NAMESPACE); + } + public function getConfigForm(PhpRenderer $renderer) { $services = $this->getServiceLocator();