Ejemplo n.º 1
0
 public function configure()
 {
     foreach ($this->folders as $folder) {
         $configFilePath = combine_paths($folder, $this->configFileName);
         $resp = FileHelper::getInstance()->getJsonArray($configFilePath);
         if ($resp === false) {
             LogHelper::getInstance()->logFatal("could not find configuration file at " . $configFilePath);
         }
         $this->addConfig($resp);
     }
 }
Ejemplo n.º 2
0
 public function getFormats()
 {
     if (!$this->formatsLoaded) {
         foreach ($this->config["FormatFiles"] as $formatFile) {
             $configFilePath = $this->folder . DIRECTORY_SEPARATOR . $formatFile;
             $resp = FileHelper::getInstance()->getJsonArray($configFilePath);
             if ($resp === false) {
                 LogHelper::getInstance()->logFatal("could not find format file at " . $configFilePath);
             } else {
                 $this->formats = array_merge($resp, $this->formats);
             }
         }
         $this->formatsLoaded = true;
     }
     return $this->formats;
 }
Ejemplo n.º 3
0
 /**
  * Methode zum Anzeigen des Contents.
  *
  * @return String Content der Applikation.
  */
 public function Display()
 {
     $view = new GenericView("import");
     if (count($this->params) > 0) {
         if ($this->params[0] == "upload") {
             $fileType = FileHelper::getInstance()->getFileTypeUploadedFile('importfile');
             $filePath = $_SERVER['DOCUMENT_ROOT'] . "/import/" . uniqid() . "." . $fileType;
             $resp = FileHelper::getInstance()->saveUploadedFile('importfile', $filePath);
             if ($resp !== true) {
                 LogHelper::getInstance()->logError(FileHelper::getInstance()->evaluateFailure($resp));
             } else {
                 $resp = DatabaseService::getInstance()->importDatabase($filePath);
                 if ($resp == true) {
                     LogHelper::getInstance()->logUserInfo(LocaleService::getInstance()->getResources()->getKey("SUCCESS_GENERAL"));
                 } else {
                     LogHelper::getInstance()->logError(DatabaseService::getInstance()->evaluateError($resp));
                 }
             }
         }
     }
     return $this->returnView($view);
 }
Ejemplo n.º 4
0
 public function setup()
 {
     $objectConfigs = $this->getConfig("Objects");
     $tableConfigs = $this->getConfig("Tables");
     $trace = TraceHelper::getInstance()->getTraceInstance("Database Service");
     /* @var $objects TableModel[] */
     $objects = array();
     foreach ($objectConfigs as $objectConfig) {
         $tableModel = new TableModel();
         $res = $tableModel->setConfig($objectConfig, true);
         if ($res === true) {
             $objects[$objectConfig["ObjectName"]] = $tableModel;
         } else {
             $trace->trace(TraceHelper::TRACE_LEVEL_ERROR, "Error in " . $objectConfig["ObjectName"] . ": " . TableModel::evaluateError($res));
             return false;
         }
     }
     $this->tables = array();
     foreach ($tableConfigs as $tableConfig) {
         $tableModel = new TableModel();
         $res = $tableModel->setConfig($tableConfig);
         if ($res === true) {
             $this->tables[$tableConfig["ObjectName"]] = $tableModel;
         } else {
             $trace->trace(TraceHelper::TRACE_LEVEL_ERROR, "Error in " . $tableConfig["ObjectName"] . ": " . TableModel::evaluateError($res));
             return false;
         }
     }
     //inheritance!
     foreach ($this->getTables() as $table) {
         $inst = $table->getInstance();
         $classes = ReflectionHelper::getInstance()->getInheritanceTree($inst);
         unset($classes[0]);
         foreach ($classes as $class) {
             if (isset($objects[$class])) {
                 $table->addProperties($objects[$class]->getProperties());
             } else {
                 $trace->trace(TraceHelper::TRACE_LEVEL_ERROR, "Base Class not found: " . $class . " for object of type " . $table->getObjectName());
                 return false;
             }
         }
     }
     //assert models are correctly configured
     $successful = true;
     foreach ($this->getTables() as $table) {
         $successful &= $table->testModel($trace);
     }
     if (!$successful) {
         $trace->trace(TraceHelper::TRACE_LEVEL_ERROR, "not all objects could setup correctly.");
         return false;
     }
     //create tables, recover data from existing table, drop table, recreate, and fill again
     foreach ($this->getTables() as $table) {
         //get data from old table;
         $sql = "SELECT * FROM " . $table->getTableName();
         $stmt = $this->executeSql($sql, null, true, true);
         $oldContent = null;
         if ($stmt !== false) {
             $oldContent = $this->fetchAllToArray($stmt);
         }
         //drop table
         if (!$this->dropTableInternal($table->getTableName(), true)) {
             if (is_array($oldContent)) {
                 $trace->trace(TraceHelper::TRACE_LEVEL_ERROR, "Cannot drop table " . $table->getTableName());
                 continue;
             }
         }
         //create new table
         $sql = $table->getCreateTableSql($this->getDatabaseDriver(), $table->getTableName());
         if (!$this->executeSql($sql)) {
             $trace->trace(TraceHelper::TRACE_LEVEL_ERROR, "Cannot create table " . $table->getTableName());
             continue;
         }
         //fill new table if old values exist
         if (is_array($oldContent)) {
             foreach ($oldContent as $entry) {
                 $values = $table->getPreparedValues($this->getDatabaseDriver(), $entry);
                 if (!$this->insertInternal($table->getTableName(), $values)) {
                     $trace->trace(TraceHelper::TRACE_LEVEL_ERROR, "could not insert values: " . json_encode($values));
                 }
             }
         }
     }
     FileHelper::getInstance()->cacheFile(FileHelper::CACHED_FILE_DATASERVICE_TABLES, FileHelper::getInstance()->serializeObject($this->getTables()));
     return true;
 }