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

Commit 4cedf63

Browse files
author
Jamie Snape
committed
Migrate archive module settings to database
1 parent bf10498 commit 4cedf63

File tree

10 files changed

+226
-167
lines changed

10 files changed

+226
-167
lines changed

modules/archive/configs/module.ini

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
; MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0.
2+
13
[global]
2-
; version of the module
3-
version = 1.0.0
4-
; full name
5-
fullname = Archive Extraction
6-
; description
7-
description = "Allows extraction of archive files into the hierarchy"
8-
; category
9-
category = Core
4+
fullname = "Archive Extractor"
5+
description = "Extract archive files into a folder hierarchy"
6+
category = "Core"
7+
uuid = "d4da29ff-cc51-4745-91be-4f934af858a5"
8+
version = "1.0.0"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
define('ARCHIVE_UNZIP_COMMAND_KEY', 'unzipCommand');
22+
define('ARCHIVE_UNZIP_COMMAND_DEFAULT_VALUE', '');
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 archive module. */
22+
class Archive_AdminController extends Mail_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 = 'Archive Module Configuration';
33+
$form = new Archive_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+
if ($value !== null) {
43+
$this->Setting->setConfig($key, $value, $this->moduleName);
44+
}
45+
}
46+
}
47+
48+
$form->populate($data);
49+
} else {
50+
$elements = $form->getElements();
51+
52+
foreach ($elements as $element) {
53+
$name = $element->getName();
54+
55+
if ($name !== 'csrf' && $name !== 'submit') {
56+
$value = $this->Setting->getValueByName($name, $this->moduleName);
57+
58+
if (!is_null($value)) {
59+
$form->setDefault($name, $value);
60+
}
61+
}
62+
}
63+
}
64+
65+
$this->view->form = $form;
66+
session_start();
67+
}
68+
}

modules/archive/controllers/ConfigController.php

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

modules/archive/controllers/components/ExtractComponent.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
/** Helper utilities for extracting archives into the Midas hierarchy */
2222
class Archive_ExtractComponent extends AppComponent
2323
{
24+
/** @var string */
25+
public $moduleName = 'archive';
26+
2427
/**
2528
* Extract an archive out of an item and into the hierarchy in place
2629
*
@@ -93,7 +96,7 @@ protected function _extractZip($bitstreamDao, $progressDao)
9396
throw new Zend_Exception('Could not write into temp directory');
9497
}
9598

96-
$nativeCommand = $this->Setting->getValueByName('unzipCommand', 'archive');
99+
$nativeCommand = $this->Setting->getValueByName(ARCHIVE_UNZIP_COMMAND_KEY, $this->moduleName);
97100

98101
if ($nativeCommand && $bitstreamDao->getSizebytes() > 1024 * 1024 * 1024
99102
) { // Only use native exe on zips over 1GB
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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/archive/constant/module.php';
22+
23+
/** Install the archive module. */
24+
class Archive_InstallScript extends MIDASModuleInstallScript
25+
{
26+
/** @var string */
27+
public $moduleName = 'archive';
28+
29+
/** Post database install. */
30+
public function postInstall()
31+
{
32+
/** @var SettingModel $settingModel */
33+
$settingModel = MidasLoader::loadModel('Setting');
34+
$settingModel->setConfig(ARCHIVE_UNZIP_COMMAND_KEY, ARCHIVE_UNZIP_COMMAND_DEFAULT_VALUE, $this->moduleName);
35+
}
36+
}

modules/archive/forms/Admin.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 archive module. */
22+
class Archive_Form_Admin extends Zend_Form
23+
{
24+
/** Initialize this form. */
25+
public function init()
26+
{
27+
$this->setName('archive_admin');
28+
$this->setMethod('POST');
29+
30+
$csrf = new Midas_Form_Element_Hash('csrf');
31+
$csrf->setSalt('W7cVNWjvC9T4heyd7AyTj52Q');
32+
$csrf->setDecorators(array('ViewHelper'));
33+
34+
$unzipCommand = new Zend_Form_Element_Text(ARCHIVE_UNZIP_COMMAND_KEY);
35+
$unzipCommand->setLabel('Unzip command');
36+
$unzipCommand->addValidator('NotEmpty', true);
37+
38+
$this->addDisplayGroup(array($unzipCommand), 'global');
39+
40+
$submit = new Zend_Form_Element_Submit('submit');
41+
$submit->setLabel('Save');
42+
43+
$this->addElements(array($csrf, $unzipCommand, $submit));
44+
}
45+
}

modules/archive/public/js/config/config.index.js

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
$this->declareVars('form', 'pageTitle');
22+
$this->headTitle($this->escape($this->pageTitle));
23+
?>
24+
25+
<div class="viewMain">
26+
<h1><?php echo $this->escape($this->pageTitle); ?></h1>
27+
<p>
28+
If you would like to use this module for extracting zip archives over 2 GB in size, you will need to enter an
29+
executable unzip command here that will be used for large zip archives because PHP does not support opening zip
30+
archives over 2 GB in size.
31+
</p>
32+
<p>
33+
The command should be the same as that you would call on the command line to unzip an archive. In the place
34+
where you would put the path of the file to unzip on the command line, instead put <i>%zip</i>. This will be
35+
substituted to the actual path of the zip file. If the command also requires an unzip directory to be
36+
explicitly specified, rather than using the current working directory, add <i>%dir</i> to the command where the
37+
output directory should be specified. Do not put quotes around the <i>%zip</i> or <i>%dir</i> arguments.
38+
</p>
39+
<p>
40+
This module will still be able to extract zip files under 2 GB in size if you leave the unzip command blank.
41+
</p>
42+
<?php echo $this->form; ?>
43+
<p><a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'index'), 'default'); ?>#tabs-modules">&laquo; Back to Modules Administration</a></p>
44+
</div>

0 commit comments

Comments
 (0)