Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 0d773aa

Browse files
author
Jamie Snape
committed
Migrate oai module settings to database
1 parent 43673f9 commit 0d773aa

File tree

15 files changed

+270
-322
lines changed

15 files changed

+270
-322
lines changed

modules/oai/configs/module.ini

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
[global]
2-
; version of the module
3-
version = 1.0.0
4-
; full name
5-
fullname = OAI
6-
; description
7-
description = Open Archives Initiative Protocol for Metadata Harvesting
8-
; category
9-
category = Core
1+
; MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0.
102

11-
repositoryname = Midas
12-
adminemail = admin@foo.com
13-
repositoryidentifier = midas.foo.com
3+
[global]
4+
fullname = "Open Archives Initiative"
5+
description = "Support the Open Archives Initiative Protocol for Metadata Harvesting"
6+
category = "Metadata"
7+
dependencies = api
8+
uuid = "f70600c0-a75a-42d0-ba47-0046c32e5ef8"
9+
version = "1.1.0"

modules/oai/controllers/forms/ConfigForm.php renamed to modules/oai/constant/module.php

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,9 @@
1818
limitations under the License.
1919
=========================================================================*/
2020

21-
/** Forms */
22-
class Oai_ConfigForm extends AppForm
23-
{
24-
/** create form */
25-
public function createConfigForm()
26-
{
27-
$form = new Zend_Form();
28-
29-
$form->setAction($this->webroot.'/oai/config/index')->setMethod('post');
30-
31-
$repositoryname = new Zend_Form_Element_Text('repositoryname');
32-
$adminemail = new Zend_Form_Element_Text('adminemail');
33-
$repositoryidentifier = new Zend_Form_Element_Text('repositoryidentifier');
34-
35-
$submit = new Zend_Form_Element_Submit('submitConfig');
36-
$submit->setLabel('Save configuration');
37-
38-
$form->addElements(array($repositoryidentifier, $adminemail, $repositoryname, $submit));
39-
40-
return $form;
41-
}
42-
}
21+
define('OAI_REPOSITORY_IDENTIFIER_KEY', 'repository_identifier');
22+
define('OAI_REPOSITORY_IDENTIFIER_DEFAULT_VALUE', 'midas.example.org');
23+
define('OAI_REPOSITORY_NAME_KEY', 'repository_name');
24+
define('OAI_REPOSITORY_NAME_DEFAULT_VALUE', 'midas');
25+
define('OAI_ADMIN_EMAIL_KEY', 'admin_email');
26+
define('OAI_ADMIN_EMAIL_DEFAULT_VALUE', 'midas@example.org');
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** Admin controller for the oai module. */
22+
class Oai_AdminController extends Oai_AppController
23+
{
24+
/** @var array */
25+
public $_models = array('Setting');
26+
27+
/** Index action */
28+
public function indexAction()
29+
{
30+
$this->requireAdminPrivileges();
31+
32+
$this->view->pageTitle = 'OAI Module Configuration';
33+
$form = new Oai_Form_Admin();
34+
35+
if ($this->getRequest()->isPost()) {
36+
$data = $this->getRequest()->getPost();
37+
38+
if ($form->isValid($data)) {
39+
$values = $form->getValues();
40+
41+
foreach ($values as $key => $value) {
42+
$this->Setting->setConfig($key, $value, $this->moduleName);
43+
}
44+
}
45+
46+
$form->populate($data);
47+
} else {
48+
$elements = $form->getElements();
49+
50+
foreach ($elements as $element) {
51+
$name = $element->getName();
52+
53+
if ($name !== 'csrf' && $name !== 'submit') {
54+
$value = $this->Setting->getValueByName($name, $this->moduleName);
55+
56+
if (!is_null($value)) {
57+
$form->setDefault($name, $value);
58+
}
59+
}
60+
}
61+
}
62+
63+
$this->view->form = $form;
64+
session_start();
65+
}
66+
}

modules/oai/controllers/ConfigController.php

Lines changed: 0 additions & 72 deletions
This file was deleted.

modules/oai/controllers/IndexController.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class Oai_IndexController extends Oai_AppController
2323
{
2424
public $_moduleModels = array();
25-
public $_models = array();
25+
public $_models = array('Setting');
2626
public $_components = array();
2727

2828
/** Before filter */
@@ -61,9 +61,6 @@ public function indexAction()
6161
$output = '';
6262
$errors = '';
6363

64-
// configuration, sorry, that's not simple :)
65-
$modulesConfig = Zend_Registry::get('configsModules');
66-
6764
if ($this->isTestingEnv()) {
6865
$_SERVER['SERVER_NAME'] = 'localhost';
6966
$_SERVER['REQUEST_METHOD'] = 'GET';
@@ -80,16 +77,16 @@ public function indexAction()
8077
$responseDate = gmstrftime('%Y-%m-%dT%H:%M:%S').'Z';
8178
$xmlheader = $XMLHEADER.' <responseDate>'.$responseDate."</responseDate>\n";
8279

83-
$repositoryName = $modulesConfig['oai']->repositoryname;
80+
$repositoryName = $this->Setting->getValueByName(OAI_REPOSITORY_NAME_KEY, $this->moduleName);
8481
$baseURL = $MY_URI;
8582
$protocolVersion = '2.0';
86-
$adminEmail = $modulesConfig['oai']->adminemail;
83+
$adminEmail = $this->Setting->getValueByName(OAI_ADMIN_EMAIL_KEY, $this->moduleName);
8784
$earliestDatestamp = 'T00:00:00Z';
8885
$deletedRecord = 'persistent';
8986
$granularity = 'YYYY-MM-DDThh:mm:ssZ';
9087
$show_identifier = false;
9188

92-
$repositoryIdentifier = $modulesConfig['oai']->repositoryidentifier;
89+
$repositoryIdentifier = $this->Setting->getValueByName(OAI_REPOSITORY_IDENTIFIER_KEY, $this->moduleName);
9390
$delimiter = ':';
9491
$idPrefix = '';
9592
$oaiprefix = "oai".$delimiter.$repositoryIdentifier.$delimiter.$idPrefix;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
require_once BASE_PATH.'/modules/oai/constant/module.php';
22+
23+
/** Install the oai module. */
24+
class Oai_InstallScript extends MIDASModuleInstallScript
25+
{
26+
/** @var string */
27+
public $moduleName = 'oai';
28+
29+
/** Post database install. */
30+
public function postInstall()
31+
{
32+
/** @var SettingModel $settingModel */
33+
$settingModel = MidasLoader::loadModel('Setting');
34+
$settingModel->setConfig(OAI_REPOSITORY_IDENTIFIER_KEY, OAI_REPOSITORY_IDENTIFIER_DEFAULT_VALUE, $this->moduleName);
35+
$settingModel->setConfig(OAI_REPOSITORY_NAME_KEY, OAI_REPOSITORY_NAME_DEFAULT_VALUE, $this->moduleName);
36+
$settingModel->setConfig(OAI_ADMIN_EMAIL_KEY, OAI_ADMIN_EMAIL_DEFAULT_VALUE, $this->moduleName);
37+
}
38+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** Upgrade the oai module to version 1.1.0. */
22+
class Oai_Upgrade_1_1_0 extends MIDASUpgrade
23+
{
24+
/** @var string */
25+
public $moduleName = 'oai';
26+
27+
/** Post database upgrade. */
28+
public function postUpgrade()
29+
{
30+
/** @var SettingModel $settingModel */
31+
$settingModel = MidasLoader::loadModel('Setting');
32+
$configPath = LOCAL_CONFIGS_PATH.DIRECTORY_SEPARATOR.$this->moduleName.'.local.ini';
33+
34+
if (file_exists($configPath)) {
35+
$config = new Zend_Config_Ini($configPath, 'global');
36+
$settingModel->setConfig(OAI_REPOSITORY_IDENTIFIER_KEY, $config->get('repositoryidentifier', OAI_REPOSITORY_IDENTIFIER_DEFAULT_VALUE), $this->moduleName);
37+
$settingModel->setConfig(OAI_REPOSITORY_NAME_KEY, $config->get('repositoryname', OAI_REPOSITORY_NAME_DEFAULT_VALUE), $this->moduleName);
38+
$settingModel->setConfig(OAI_ADMIN_EMAIL_KEY, $config->get('adminemail', OAI_ADMIN_EMAIL_DEFAULT_VALUE), $this->moduleName);
39+
40+
$config = new Zend_Config_Ini($configPath, null, true);
41+
unset($config->global->repositoryidentifier);
42+
unset($config->global->repositoryname);
43+
unset($config->global->adminemail);
44+
45+
$writer = new Zend_Config_Writer_Ini();
46+
$writer->setConfig($config);
47+
$writer->setFilename($configPath);
48+
$writer->write();
49+
} else {
50+
$settingModel->setConfig(OAI_REPOSITORY_IDENTIFIER_KEY, OAI_REPOSITORY_IDENTIFIER_DEFAULT_VALUE, $this->moduleName);
51+
$settingModel->setConfig(OAI_REPOSITORY_NAME_KEY, OAI_REPOSITORY_NAME_DEFAULT_VALUE, $this->moduleName);
52+
$settingModel->setConfig(OAI_ADMIN_EMAIL_KEY, OAI_ADMIN_EMAIL_DEFAULT_VALUE, $this->moduleName);
53+
}
54+
}
55+
}

modules/oai/forms/Admin.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** Admin form for the oai module. */
22+
class Oai_Form_Admin extends Zend_Form
23+
{
24+
/** Initialize this form. */
25+
public function init()
26+
{
27+
$this->setName('oai_admin');
28+
$this->setMethod('POST');
29+
30+
$csrf = new Midas_Form_Element_Hash('csrf');
31+
$csrf->setSalt('YTVEA8QwsJqFaPfcnEugjKrM');
32+
$csrf->setDecorators(array('ViewHelper'));
33+
34+
$repositoryName = new Zend_Form_Element_Text(OAI_REPOSITORY_NAME_KEY);
35+
$repositoryName->setLabel('OAI Repository Name');
36+
$repositoryName->setRequired(true);
37+
$repositoryName->addValidator('NotEmpty', true);
38+
39+
$repositoryIdentifier = new Zend_Form_Element_Text(OAI_REPOSITORY_IDENTIFIER_KEY);
40+
$repositoryIdentifier->setLabel('OAI Repository Identifier');
41+
$repositoryIdentifier->setRequired(true);
42+
$repositoryIdentifier->addValidator('NotEmpty', true);
43+
44+
$adminEmail = new Zend_Form_Element_Text(OAI_ADMIN_EMAIL_KEY);
45+
$adminEmail->setLabel('Admin Email Address');
46+
$adminEmail->setRequired(true);
47+
$adminEmail->addValidator('NotEmpty', true);
48+
$adminEmail->addValidator('EmailAddress', true);
49+
50+
$this->addDisplayGroup(array($repositoryName, $repositoryIdentifier, $adminEmail), 'global');
51+
52+
$submit = new Zend_Form_Element_Submit('submit');
53+
$submit->setLabel('Save');
54+
55+
$this->addElements(array($csrf, $repositoryName, $repositoryIdentifier, $adminEmail, $submit));
56+
}
57+
}

0 commit comments

Comments
 (0)