Do not overwrite existing format namespace definitions

This commit is contained in:
Sebastian Meyer 2013-01-10 14:24:01 +01:00
parent 3c20443dff
commit 800ecc9e34
4 changed files with 154 additions and 41 deletions

View File

@ -1,3 +1,6 @@
# cat=Basic; type=user[EXT:dlf/hooks/class.tx_dlf.em.php:tx_dlf_em->checkMetadataFormats]; label=LLL:EXT:dlf/locallang.xml:config.metadataFormats
metadataFormats = 0
# cat=Basic; type=user[EXT:dlf/hooks/class.tx_dlf_em.php:tx_dlf_em->checkCliUserGroup]; label=LLL:EXT:dlf/locallang.xml:config.cliUserGroup
cliUserGroup = 0

View File

@ -1,21 +0,0 @@
--
-- Table structure for table 'tx_dlf_formats'
--
CREATE TABLE tx_dlf_formats (
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
tstamp int(11) DEFAULT '0' NOT NULL,
crdate int(11) DEFAULT '0' NOT NULL,
cruser_id int(11) DEFAULT '0' NOT NULL,
deleted tinyint(4) DEFAULT '0' NOT NULL,
type tinytext NOT NULL,
root tinytext NOT NULL,
namespace text NOT NULL,
class text NOT NULL,
PRIMARY KEY (uid),
KEY parent (pid)
);
INSERT INTO tx_dlf_formats VALUES ('1', '0', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), '0', '0', 'MODS', 'mods', 'http://www.loc.gov/mods/v3', 'tx_dlf_mods');
INSERT INTO tx_dlf_formats VALUES ('2', '0', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), '0', '0', 'TEIHDR', 'teiHeader', 'http://www.tei-c.org/ns/1.0', 'tx_dlf_teihdr');

View File

@ -37,6 +37,14 @@
*/
class tx_dlf_em {
/**
* This holds the current configuration
*
* @var array
* @access protected
*/
protected $conf = array ();
/**
* This holds the output ready to return
*
@ -57,28 +65,22 @@ class tx_dlf_em {
*/
public function checkSolrConnection(&$params, &$pObj) {
// Load localization file.
$GLOBALS['LANG']->includeLLFile('EXT:dlf/locallang.xml');
// Get Solr credentials.
$conf = array_merge((array) unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dlf']), (array) t3lib_div::_POST('data'));
// Prepend username and password to hostname.
if (!empty($conf['solrUser']) && !empty($conf['solrPass'])) {
if (!empty($this->conf['solrUser']) && !empty($this->conf['solrPass'])) {
$host = $conf['solrUser'].':'.$conf['solrPass'].'@'.($conf['solrHost'] ? $conf['solrHost'] : 'localhost');
$host = $this->conf['solrUser'].':'.$this->conf['solrPass'].'@'.(!empty($this->conf['solrHost']) ? $this->conf['solrHost'] : 'localhost');
} else {
$host = (!empty($conf['solrHost']) ? $conf['solrHost'] : 'localhost');
$host = (!empty($this->conf['solrHost']) ? $this->conf['solrHost'] : 'localhost');
}
// Set port if not set.
$port = (!empty($conf['solrPort']) ? t3lib_div::intInRange($conf['solrPort'], 0, 65535, 8180) : 8180);
$port = (!empty($this->conf['solrPort']) ? t3lib_div::intInRange($this->conf['solrPort'], 0, 65535, 8180) : 8180);
// Trim path and append trailing slash.
$path = (!empty($conf['solrPath']) ? trim($conf['solrPath'], '/').'/' : '');
$path = (!empty($this->conf['solrPath']) ? trim($this->conf['solrPath'], '/').'/' : '');
// Build request URI.
$url = 'http://'.$host.':'.$port.'/'.$path.'admin/cores';
@ -86,7 +88,7 @@ class tx_dlf_em {
$context = stream_context_create(array (
'http' => array (
'method' => 'GET',
'user_agent' => (!empty($conf['useragent']) ? $conf['useragent'] : ini_get('user_agent'))
'user_agent' => (!empty($this->conf['useragent']) ? $this->conf['useragent'] : ini_get('user_agent'))
)
));
@ -528,20 +530,14 @@ class tx_dlf_em {
*/
public function checkCliUserGroup(&$params, &$pObj) {
// Load localization file.
$GLOBALS['LANG']->includeLLFile('EXT:dlf/locallang.xml');
// Get current configuration.
$conf = array_merge((array) unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dlf']), (array) t3lib_div::_POST('data'));
// Check if usergroup "_cli_dlf" exists and is configured properly.
$groupUid = $this->checkCliGroup(empty($conf['makeCliUserGroup']));
$groupUid = $this->checkCliGroup(empty($this->conf['makeCliUserGroup']));
// Save output because it will be overwritten by the user check method.
$content = $this->content;
// Check if user "_cli_dlf" exists and is configured properly.
$userUid = $this->checkCliUser(empty($conf['makeCliUserGroup']), $groupUid);
$userUid = $this->checkCliUser(empty($this->conf['makeCliUserGroup']), $groupUid);
// Merge output from usergroup and user checks.
$this->content .= $content;
@ -575,6 +571,127 @@ class tx_dlf_em {
}
/**
* Make sure the essential namespaces are defined.
*
* @access public
*
* @param array &$params: An array with parameters
* @param t3lib_tsStyleConfig &$pObj: The parent object
*
* @return string Message informing the user of success or failure
*/
public function checkMetadataFormats(&$params, &$pObj) {
$nsDefined = array (
'MODS' => FALSE,
'TEIHDR' => FALSE
);
// Check if formats "MODS" and "TEIHDR" exist.
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'type',
'tx_dlf_formats',
'(type='.$GLOBALS['TYPO3_DB']->fullQuoteStr('MODS', 'tx_dlf_formats').' OR type='.$GLOBALS['TYPO3_DB']->fullQuoteStr('TEIHDR', 'tx_dlf_formats').')'.tx_dlf_helper::whereClause('tx_dlf_formats')
);
while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
$nsDefined[$resArray['type']] = TRUE;
}
// Build data array.
$data = array ();
// Add MODS namespace.
if (!$nsDefined['MODS']) {
$data['tx_dlf_formats'][uniqid('NEW')] = array (
'pid' => 0,
'type' => 'MODS',
'root' => 'mods',
'namespace' => 'http://www.loc.gov/mods/v3',
'class' => 'tx_dlf_mods'
);
}
// Add TEIHDR namespace.
if (!$nsDefined['TEIHDR']) {
$data['tx_dlf_formats'][uniqid('NEW')] = array (
'pid' => 0,
'type' => 'TEIHDR',
'root' => 'teiHeader',
'namespace' => 'http://www.tei-c.org/ns/1.0',
'class' => 'tx_dlf_teihdr'
);
}
if (!empty($data)) {
// Process changes.
$substUid = tx_dlf_helper::processDBasAdmin($data);
if (!empty($substUid)) {
$message = t3lib_div::makeInstance(
't3lib_FlashMessage',
$GLOBALS['LANG']->getLL('metadataFormats.nsCreatedMsg'),
$GLOBALS['LANG']->getLL('metadataFormats.nsCreated'),
t3lib_FlashMessage::INFO,
FALSE
);
} else {
$message = t3lib_div::makeInstance(
't3lib_FlashMessage',
$GLOBALS['LANG']->getLL('metadataFormats.nsNotCreatedMsg'),
$GLOBALS['LANG']->getLL('metadataFormats.nsNotCreated'),
t3lib_FlashMessage::ERROR,
FALSE
);
}
} else {
$message = t3lib_div::makeInstance(
't3lib_FlashMessage',
$GLOBALS['LANG']->getLL('metadataFormats.nsOkayMsg'),
$GLOBALS['LANG']->getLL('metadataFormats.nsOkay'),
t3lib_FlashMessage::OK,
FALSE
);
}
$this->content .= $message->render();
return $this->content;
}
/**
* This is the constructor.
*
* @access public
*
* @return void
*/
public function __construct() {
// Load localization file.
$GLOBALS['LANG']->includeLLFile('EXT:dlf/locallang.xml');
// Get current configuration.
$this->conf = array_merge((array) unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dlf']), (array) t3lib_div::_POST('data'));
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dlf/hooks/class.tx_dlf_em.php']) {

View File

@ -122,6 +122,7 @@
<label index="tt_content.dlf_statistics">DLF: Statistics</label>
<label index="tt_content.dlf_toc">DLF: Table of Contents</label>
<label index="tt_content.dlf_toolbox">DLF: Toolbox</label>
<label index="config.metadataFormats">Default metadata namespaces</label>
<label index="config.cliUserGroup">CLI user/group</label>
<label index="config.makeCliUserGroup">Create and configure CLI user/group automatically?: (default is "FALSE")</label>
<label index="config.useragent">DLF User-Agent: (default is "Goobi.Presentation")</label>
@ -140,6 +141,12 @@
<label index="solr.status">The status code returned by Apache Solr is &lt;strong&gt;%s&lt;/strong&gt;.</label>
<label index="solr.notConnected">Connection failed!</label>
<label index="solr.error">Apache Solr was not reachable under &lt;strong&gt;%s&lt;/strong&gt;.</label>
<label index="metadataFormats.nsOkay">Default namespaces found!</label>
<label index="metadataFormats.nsOkayMsg">The namespace definitions for MODS and TEIHDR do exist.</label>
<label index="metadataFormats.nsCreated">Default namespaces created successfully!</label>
<label index="metadataFormats.nsCreatedMsg">The namespace definitions for MODS and/or TEIHDR were created properly.</label>
<label index="metadataFormats.nsNotCreated">Default namespaces not found!</label>
<label index="metadataFormats.nsNotCreatedMsg">The namespace definitions for MODS and/or TEIHDR do not exist and could not be created.</label>
<label index="cliUserGroup.usrRealName">Goobi.Presentation command line indexer</label>
<label index="cliUserGroup.usrOkay">User "_cli_dlf" found!</label>
<label index="cliUserGroup.usrOkayMsg">The backend user for the command line indexer exists and is configured properly.</label>
@ -287,6 +294,7 @@
<label index="tt_content.dlf_statistics">DLF: Statistik</label>
<label index="tt_content.dlf_toc">DLF: Inhaltsverzeichnis</label>
<label index="tt_content.dlf_toolbox">DLF: Werkzeugkasten</label>
<label index="config.metadataFormats">Standard-Namensräume für Metadaten</label>
<label index="config.cliUserGroup">CLI Benutzer/Gruppe</label>
<label index="config.makeCliUserGroup">CLI Benutzer/Gruppe automatisch anlegen?: (Standard ist "FALSE")</label>
<label index="config.useragent">DLF User-Agent: (Standard ist "Goobi.Presentation")</label>
@ -305,6 +313,12 @@
<label index="solr.status">Apache Solr gibt den Statuscode &lt;strong&gt;%s&lt;/strong&gt; zurück.</label>
<label index="solr.notConnected">Verbindung fehlgeschlagen!</label>
<label index="solr.error">Apache Solr ist unter &lt;strong&gt;%s&lt;/strong&gt; nicht erreichbar.</label>
<label index="metadataFormats.nsOkay">Standard-Namensräume gefunden!</label>
<label index="metadataFormats.nsOkayMsg">Die Standard-Namensräume für MODS und TEIHDR sind definiert.</label>
<label index="metadataFormats.nsCreated">Standard-Namensräume erfolgreich angelegt!</label>
<label index="metadataFormats.nsCreatedMsg">Die Standard-Namensräume für MODS und/oder TEIHDR wurden erfolgreich definiert.</label>
<label index="metadataFormats.nsNotCreated">Standard-Namensräume nicht gefunden!</label>
<label index="metadataFormats.nsNotCreatedMsg">Die Standard-Namensräume für MODS und/oder TEIHDR konnten nicht definiert werden.</label>
<label index="cliUserGroup.usrRealName">Goobi.Presentation Kommandozeilen-Indexierungsdienst</label>
<label index="cliUserGroup.usrOkay">Nutzer "_cli_dlf" gefunden!</label>
<label index="cliUserGroup.usrOkayMsg">Der Nutzer für den Kommandozeilen-Indexierungsdienst ist korrekt konfiguriert und aktiviert.</label>