Skip to content
This repository
Browse code

Merge branch 'feature/PublicDataEUFixes' into develop

  • Loading branch information...
commit 67162219834bf252bcfe6604b15fa2191681eb38 2 parents 1f9c4c7 + a517c3a
Philipp Frischmuth authored April 10, 2012
16  application/classes/OntoWiki/Menu/Registry.php
@@ -99,15 +99,13 @@ private function _getApplicationMenu()
99 99
         $owApp = OntoWiki::getInstance();
100 100
 
101 101
         // user sub menu
102  
-        if (
103  
-            $owApp->erfurt->isActionAllowed('RegisterNewUser') &&
104  
-            !(
105  
-                isset($owApp->config->ac) &&
106  
-                ((boolean)$owApp->config->ac->deactivateRegistration === true)
107  
-            )
108  
-        ) {
109  
-            $userMenu = new OntoWiki_Menu();
110  
-            $userMenu->setEntry('Register New User', $owApp->config->urlBase . 'application/register');
  102
+        if ($owApp->erfurt->isActionAllowed('RegisterNewUser') && 
  103
+            !(isset($owApp->config->ac) && ((boolean)$owApp->config->ac->deactivateRegistration === true))) {
  104
+            
  105
+            if (!($owApp->erfurt->getAc() instanceof Erfurt_Ac_None)) {
  106
+                $userMenu = new OntoWiki_Menu();
  107
+                $userMenu->setEntry('Register New User', $owApp->config->urlBase . 'application/register');
  108
+            }
111 109
         }
112 110
         if ($owApp->user && !$owApp->user->isAnonymousUser()) {
113 111
             if (!isset($userMenu)) {
3  config.ini-dist
@@ -50,6 +50,9 @@ store.arc.password = "ow"
50 50
 store.arc.host = "localhost"
51 51
 store.arc.store = "ef"
52 52
 
  53
+;store.sparql.serviceUrl = "http://dbpedia.org/sparql";
  54
+;store.sparql.graphs[] = "http://dbpedia.org"
  55
+
53 56
 ;;;;
54 57
 ;; Comparer backend specific options
55 58
 ;;
4  extensions/account/LoginModule.php
@@ -82,6 +82,10 @@ public function getContents()
82 82
 
83 83
     public function shouldShow()
84 84
     {
  85
+        if ($this->_owApp->erfurt->getAc() instanceof Erfurt_Ac_None) {
  86
+            return false;
  87
+        }
  88
+        
85 89
         if (!$this->_owApp->user || $this->_owApp->user->isAnonymousUser()) {
86 90
             return true;
87 91
         }
13  extensions/community/LastchangesModule.php
@@ -15,6 +15,10 @@ class LastchangesModule extends OntoWiki_Module {
15 15
     public function init() {
16 16
     // enabling versioning
17 17
         $this->versioning = $this->_erfurt->getVersioning();
  18
+        if (!$this->versioning instanceof Erfurt_Versioning) {
  19
+            return;
  20
+        }
  21
+        
18 22
         if (!$this->versioning->isVersioningEnabled()) {
19 23
             $this->view->warningmessage = 'Versioning/history is currently disabled. This means, you can not see the latest changes.';
20 24
         } else {
@@ -36,6 +40,15 @@ public function init() {
36 40
     public function getTitle() {
37 41
         return 'Latest Changes';
38 42
     }
  43
+    
  44
+    public function shouldShow()
  45
+    {
  46
+        if (!$this->versioning instanceof Erfurt_Versioning) {
  47
+            return false;
  48
+        }
  49
+        
  50
+        return true;
  51
+    }
39 52
 
40 53
     public function getContents() {
41 54
         $url     = new OntoWiki_Url(array('route' => 'properties'), array('r'));
2  libraries/Erfurt
... ...
@@ -1 +1 @@
1  
-Subproject commit aeb445f2b6af9d30dc7d43b760e84c4adb1989ed
  1
+Subproject commit 771ee661cd1f1a441c00a8ae4b91a200fed6dcad
218  scripts/owadmin.php
... ...
@@ -0,0 +1,218 @@
  1
+<?php
  2
+define('SCRIPT_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
  3
+
  4
+if (!defined('APPLICATION_PATH')) {
  5
+    define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
  6
+}
  7
+set_include_path(implode(PATH_SEPARATOR, array(
  8
+    APPLICATION_PATH . '/../libraries',
  9
+    get_include_path(),
  10
+)));
  11
+require_once 'Zend/Loader/Autoloader.php';
  12
+Zend_Loader_Autoloader::getInstance();
  13
+
  14
+// Define some CLI options
  15
+$getopt = new Zend_Console_Getopt(array(
  16
+    'virtload'  => 'Import files in data directory into Virtuoso',
  17
+    'virtclear' => 'Clear a specified graph',
  18
+    'help|h'   => 'Help -- usage message',
  19
+));
  20
+try {
  21
+    $getopt->parse();
  22
+} catch (Zend_Console_Getopt_Exception $e) {
  23
+    // Bad options passed: report usage
  24
+    echo $e->getUsageMessage();
  25
+    return false;
  26
+}
  27
+
  28
+// If help requested, report usage message
  29
+if ($getopt->getOption('h')) {
  30
+    echo $getopt->getUsageMessage();
  31
+    return true;
  32
+} else if ($getopt->getOption('virtload')) {
  33
+    return _importData();
  34
+} else if ($getopt->getOption('virtclear')) {
  35
+    return _clearGraph();
  36
+} else {
  37
+    echo $getopt->getUsageMessage();
  38
+    return true;
  39
+}
  40
+
  41
+
  42
+return true;
  43
+
  44
+/* Functions */
  45
+
  46
+function _clearGraph()
  47
+{
  48
+    $graph = _chooseGraph();
  49
+    if (!$graph) {
  50
+        return false;
  51
+    }
  52
+    $command = "isql VERBOSE=OFF \"EXEC=sparql DELETE FROM <$graph> {?s ?p ?o} WHERE {?s ?p ?o}\" 2>&1 1> /dev/null";
  53
+    $output = shell_exec($command);
  54
+    if (null !== $output) {
  55
+        return false;
  56
+    }
  57
+    
  58
+    echo "DONE!" . PHP_EOL;
  59
+    return true;
  60
+}
  61
+
  62
+function _importData()
  63
+{
  64
+    // Check for files
  65
+    $importFiles = array();
  66
+    $files = scandir(SCRIPT_DIR . 'data');
  67
+    foreach ($files as $file) {
  68
+        if ($file[0] === '.') {
  69
+            continue;
  70
+        }
  71
+        $importFiles[$file] = SCRIPT_DIR . 'data' . DIRECTORY_SEPARATOR . $file;
  72
+    }
  73
+    
  74
+    $failed = false;
  75
+    $failReason = '';
  76
+    foreach ($importFiles as $file=>$fullPath) {
  77
+        $ending = substr($file, -4);
  78
+        switch ($ending) {
  79
+            case '.ttl':
  80
+                break;
  81
+            case '.owl':
  82
+            case '.rdf':
  83
+                $newPath = SCRIPT_DIR . 'tmp' . DIRECTORY_SEPARATOR . 'sourceNtriples.ttl';
  84
+                $cmd = "rapper -gqo ntriples '$fullPath' 2>&1 1> /dev/null > '$newPath'";
  85
+                $output = shell_exec($cmd);
  86
+                if (null !== $output) {
  87
+                    echo 'Error while converting source file to TTL.';
  88
+                    exit;
  89
+                }
  90
+                $fullPath = $newPath;
  91
+                break;
  92
+            default: 
  93
+                continue;
  94
+        }
  95
+        
  96
+        
  97
+        
  98
+        echo "Preparing import of file $file now." . PHP_EOL;
  99
+        $graph = _chooseGraph();
  100
+        if (!$graph) {
  101
+            $failed = true;
  102
+            $failReason = 'Invalid Graph!';
  103
+            break;
  104
+        }
  105
+        echo "Will import data into graph <$graph>." . PHP_EOL;
  106
+        
  107
+        $splitFiles = _splitFiles($fullPath);
  108
+        $count = count($splitFiles);
  109
+        foreach ($splitFiles as $i=>$splitFile) {
  110
+            $progress = round(($i/$count)*100.0);
  111
+            echo "\rImporting $file now: $progress%";
  112
+            if (!$failed) {
  113
+                $result = _importFile($splitFile, $graph);
  114
+            }
  115
+            unlink($splitFile);
  116
+            if (!$result) {
  117
+                $failed = true;
  118
+                $failReason = 'Import failed';
  119
+            }
  120
+        }
  121
+        
  122
+        // Move file to done dir!
  123
+        if (!$failed) {
  124
+            copy($fullPath, SCRIPT_DIR.'done'.DIRECTORY_SEPARATOR.$file);
  125
+            unlink($fullPath);
  126
+        }
  127
+        
  128
+        echo PHP_EOL;
  129
+    }
  130
+    
  131
+    if ($failed) {
  132
+        echo $failReason . PHP_EOL;
  133
+    } else {
  134
+        echo 'DONE!' . PHP_EOL;
  135
+    }
  136
+    return true;
  137
+}
  138
+
  139
+function _splitFiles($fullPath)
  140
+{
  141
+    $splitFiles = array();
  142
+    
  143
+    $fHandle = fopen($fullPath, 'r');
  144
+    $fileCount = 0;
  145
+    $i = 0;
  146
+    $currentContent = '';
  147
+    if ($fHandle) {
  148
+        while ($line = fgets($fHandle)) {
  149
+            $currentContent .= $line;
  150
+            
  151
+            $i++;
  152
+            if ($i === 10000) {
  153
+                $tmp = SCRIPT_DIR . 'tmp' . DIRECTORY_SEPARATOR . $fileCount++;
  154
+                file_put_contents($tmp, $currentContent);
  155
+                $splitFiles[] = $tmp;
  156
+                $i = 0;
  157
+                $currentContent = '';
  158
+            }
  159
+        }
  160
+        if ($currentContent !== '') {
  161
+            $tmp = SCRIPT_DIR . 'tmp' . DIRECTORY_SEPARATOR . $fileCount++;
  162
+            file_put_contents($tmp, $currentContent);
  163
+            $splitFiles[] = $tmp;
  164
+        }
  165
+    }
  166
+    fclose($fHandle);
  167
+    
  168
+    return $splitFiles;
  169
+}
  170
+
  171
+function _chooseGraph()
  172
+{
  173
+    $command = 'isql VERBOSE=OFF "EXEC=SELECT ID_TO_IRI(REC_GRAPH_IID) AS GRAPH FROM DB.DBA.RDF_EXPLICITLY_CREATED_GRAPH"';
  174
+    
  175
+    $output = shell_exec($command);
  176
+    $outputLines = explode("\n", $output);
  177
+    
  178
+    $startReached = false;
  179
+    $graphs = array();
  180
+    foreach ($outputLines as $line) {
  181
+        $trimmedLine = trim($line);
  182
+        if ($trimmedLine === '') {
  183
+            continue;
  184
+        }
  185
+        if (strpos($trimmedLine, '______________________________') !== false) {
  186
+            $startReached = true;
  187
+            continue;
  188
+        }
  189
+        if ($startReached) {
  190
+            $graphs[] = $line;
  191
+        }
  192
+    }
  193
+    
  194
+    echo "Choose a graph:\n";
  195
+    foreach ($graphs as $i=>$g) {
  196
+        echo "    ($i) $g" . PHP_EOL;
  197
+    }
  198
+    echo "Just type in the number: ";
  199
+    $input = intval(trim(fgets(STDIN)));
  200
+    
  201
+    if (isset($graphs[$input])) {
  202
+        return $graphs[$input];
  203
+    }
  204
+    
  205
+    return false;
  206
+}
  207
+
  208
+function _importFile($file, $graph)
  209
+{
  210
+    $command = "isql 1111 dba dba \"EXEC=TTLP(file_to_string_output('$file'), '', '$graph', 255)\" 2>&1 1> /dev/null";
  211
+    $output = shell_exec($command);
  212
+    if (null !== $output) {
  213
+        var_dump($output);exit;
  214
+        return false;
  215
+    }
  216
+    
  217
+    return true;
  218
+}

0 notes on commit 6716221

Please sign in to comment.
Something went wrong with that request. Please try again.