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

Commit 9c6ea04

Browse files
author
Charles Ma
committed
ENH: fixed bug #159 Added metadata extractor module
1 parent a017f20 commit 9c6ea04

File tree

16 files changed

+338
-15
lines changed

16 files changed

+338
-15
lines changed

core/controllers/components/UploadComponent.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ public function createUploadedItem($userDao, $name, $path, $parent = null, $lice
306306
$itemRevisionModel->addBitstream($itemRevisionDao, $bitstreamDao);
307307

308308
$this->getLogger()->info(__METHOD__." Upload ok :".$path);
309+
Zend_Registry::get('notifier')->notifyEvent("EVENT_CORE_UPLOAD_FILE", array($item->toArray(), $itemRevisionDao->toArray()));
309310
return $item;
310311
}//end createUploadedItem
311312

@@ -408,6 +409,7 @@ public function createNewRevision($userDao, $name, $path, $item_revision, $chang
408409
$itemRevisionModel->addBitstream($itemRevisionDao, $bitstreamDao);
409410

410411
$this->getLogger()->info(__METHOD__." Upload ok :".$path);
412+
Zend_Registry::get('notifier')->notifyEvent("EVENT_CORE_UPLOAD_FILE", array($itemRevisionDao->getItem()->toArray(), $itemRevisionDao->toArray()));
411413
return $item;
412414
}//end
413415
} // end class UploadComponent

core/models/base/ItemRevisionModelBase.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ function addBitstream($itemRevisionDao, $bitstreamDao)
6161
$item->setDateCreation(date('c'));
6262

6363
$modulesThumbnail = Zend_Registry::get('notifier')->notifyEvent("EVENT_CORE_CREATE_THUMBNAIL", array($item));
64-
if(empty($modulesThumbnail))
64+
$notifications = Zend_Registry::get('notifier')->getNotifications();
65+
66+
$createThumb = false;
67+
if(!isset($notifications["EVENT_CORE_CREATE_THUMBNAIL"]) || empty($notifications["EVENT_CORE_CREATE_THUMBNAIL"]))
6568
{
6669
$mime = $bitstreamDao->getMimetype();
6770
$tmpfile = $bitstreamDao->getPath();
@@ -152,20 +155,6 @@ function addBitstream($itemRevisionDao, $bitstreamDao)
152155
imagedestroy($src);
153156
}
154157
}
155-
else
156-
{
157-
$createThumb = false;
158-
//TODO
159-
/*
160-
require_once BASE_PATH.'/core/controllers/components/FilterComponent.php';
161-
$filterComponent = new FilterComponent();
162-
$thumbnailCreator = $filterComponent->getFilter('ThumbnailCreator');
163-
$thumbnailCreator->inputFile = $bitstreamDao->getFullPath();
164-
$thumbnailCreator->inputName = $bitstreamDao->getName();
165-
$hasThumbnail = $thumbnailCreator->process();
166-
167-
*/
168-
}
169158

170159
if($createThumb)
171160
{

core/models/base/MetadataModelBase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function addMetadata($type, $element, $qualifier, $description)
6464
* @return MetadataDao */
6565
function addMetadataValue($itemRevisionDao, $type, $element, $qualifier, $value)
6666
{
67+
6768
if(!$itemRevisionDao instanceof $itemRevisionDao)
6869
{
6970
throw new Zend_Exception("Error parameters.");

library/MIDAS/MIDASNotifier.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ class MIDAS_Notifier
1818
private $tasksByModule = array();
1919
public $notifications = array();
2020

21+
/** get Notification */
22+
public function getNotifications()
23+
{
24+
return $this->notifications;
25+
}
26+
27+
/** get Tasks */
28+
public function getTaks()
29+
{
30+
return $this->tasks;
31+
}
32+
2133
/** init the notifier*/
2234
public function __construct()
2335
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*=========================================================================
4+
MIDAS Server
5+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
6+
69328 Lyon, FRANCE.
7+
8+
See Copyright.txt for details.
9+
This software is distributed WITHOUT ANY WARRANTY; without even
10+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11+
PURPOSE. See the above copyright notices for more information.
12+
=========================================================================*/
13+
14+
class Metadataextractor_AppController extends MIDAS_GlobalModule
15+
{
16+
public $moduleName='metadataextractor';
17+
} //end class
18+
?>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/** notification manager*/
3+
class Metadataextractor_Notification extends MIDAS_Notification
4+
{
5+
public $_moduleComponents=array('Extractor');
6+
public $moduleName = 'metadataextractor';
7+
8+
/** init notification process*/
9+
public function init()
10+
{
11+
$this->addTask("TASK_METADATAEXTRACTOR_EXTRACT", 'extractMetaData', "Extract Metadata. Parameters: Item, Revision");
12+
$this->addEvent('EVENT_CORE_UPLOAD_FILE', 'TASK_METADATAEXTRACTOR_EXTRACT');
13+
}//end init
14+
15+
/** get Config Tabs */
16+
public function extractMetaData($params)
17+
{
18+
$this->ModuleComponent->Extractor->extract($params[1]);
19+
return;
20+
}
21+
} //end class
22+
?>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.local.ini
2+
*.local.ini.old
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[global]
2+
; version of the module
3+
version = 1.0
4+
; full name
5+
fullname= MetaData Extractor
6+
; description
7+
description= Extract meta data from common files
8+
;Category
9+
category = Filter
10+
11+
;hachoir-metadata command
12+
hachoir = "python hachoir-metadata"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
6+
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
13+
?>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
class Metadataextractor_ConfigController extends Metadataextractor_AppController
4+
{
5+
public $_moduleForms=array('Config');
6+
public $_components=array('Utility', 'Date');
7+
8+
9+
/** index action*/
10+
function indexAction()
11+
{
12+
if(!$this->logged||!$this->userSession->Dao->getAdmin()==1)
13+
{
14+
throw new Zend_Exception("You should be an administrator");
15+
}
16+
17+
if(file_exists(BASE_PATH."/core/configs/metadataextractor.local.ini"))
18+
{
19+
$applicationConfig = parse_ini_file(BASE_PATH."/core/configs/".$this->moduleName.".local.ini", true);
20+
}
21+
else
22+
{
23+
$applicationConfig = parse_ini_file(BASE_PATH.'/modules/".$this->moduleName."/configs/module.ini', true);
24+
}
25+
$configForm = $this->ModuleForm->Config->createConfigForm();
26+
27+
$formArray = $this->getFormAsArray($configForm);
28+
$formArray['hachoir']->setValue($applicationConfig['global']['hachoir']);
29+
30+
$this->view->configForm = $formArray;
31+
32+
if($this->_request->isPost())
33+
{
34+
$this->_helper->layout->disableLayout();
35+
$this->_helper->viewRenderer->setNoRender();
36+
$submitConfig = $this->_getParam('submitConfig');
37+
if(isset($submitConfig))
38+
{
39+
if(file_exists(BASE_PATH."/core/configs/".$this->moduleName.".local.ini.old"))
40+
{
41+
unlink(BASE_PATH."/core/configs/".$this->moduleName.".local.ini.old");
42+
}
43+
if(file_exists(BASE_PATH."/core/configs/".$this->moduleName.".local.ini"))
44+
{
45+
rename(BASE_PATH."/core/configs/".$this->moduleName.".local.ini",BASE_PATH."/core/configs/".$this->moduleName.".local.ini.old");
46+
}
47+
$applicationConfig['global']['hachoir'] = $this->_getParam('hachoir');
48+
$this->Component->Utility->createInitFile(BASE_PATH."/core/configs/".$this->moduleName.".local.ini", $applicationConfig);
49+
echo JsonComponent::encode(array(true, 'Changed saved'));
50+
}
51+
}
52+
}
53+
54+
}//end class

0 commit comments

Comments
 (0)