-
Notifications
You must be signed in to change notification settings - Fork 3
/
Importer.php
97 lines (85 loc) · 2.72 KB
/
Importer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* This file is part of the {@link http://ontowiki.net OntoWiki} project.
*
* @copyright Copyright (c) 2008, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/
require_once('ImporterInterface.php');
/**
* Abstract Class of CSV Importer
*
* @category OntoWiki
* @package Extensions
* @subpackage Csvimport
* @copyright Copyright (c) 2010, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/
abstract class Importer implements ImporterInterface
{
protected $configuration;
protected $storedConfigurations;
protected $uploadedFile;
protected $parsedFile;
protected $viewElements;
protected $componentConfig;
protected $view;
protected $parserInstructions = array();
public function __construct(&$view, $componentConfig, $parserInstructions = array()) {
$this->view = $view;
$this->componentConfig = $componentConfig;
$this->parserInstructions = $parserInstructions;
$this->initLog();
}
public function setConfiguration($configuration) {
$this->configuration = $configuration;
}
public function setStoredConfigurations($configurations) {
$this->storedConfigurations = $configurations;
}
public function setFile($uploadedFile) {
$this->uploadedFile = $uploadedFile;
if (is_readable($this->uploadedFile)) {
$this->parseFile();
}
}
public function getParsedFile() {
return $this->parsedFile;
}
public function setParsedFile($parsedFile) {
$this->parsedFile = $parsedFile;
}
public function getViewElements() {
if (!empty($this->viewElements))
return $this->viewElements;
return array();
}
public static function initLog(){
//$path = 'extensions/csvimport/logs/';
$path = 'logs/';
//if(!is_writable($path)) return -1;
if(!is_dir($path)) {
if(!mkdir($path, 0777)){
echo "something was wrong while creating log at : " . $path;
return 0;
}
}
$fp = fopen($path.'importer.log', 'w+');
fwrite($fp, "");
fclose($fp);
}
public static function logEvent($event){
//$path = 'extensions/csvimport/';
$path = 'logs/';
//if(!is_writable($path)) return -1;
if(!is_dir($path)) {
if(!mkdir($path, 0777)){
echo "something was wrong while creating log at : " . $path;
return 0;
}
}
$fp = fopen($path.'importer.log', 'a+');
fwrite($fp, $event."\n");
fclose($fp);
}
}