Ejemplo n.º 1
0
 /**
  * Parse and process the data content.
  *
  * insert => insert rows.
  * update => make some changes into the rows.
  * delete => delete rows.
  *
  * The values ##Module_id## are reemplaces with the moduleId value
  *
  * @param array $array Array from the json data with the changes.
  *
  * @return void
  */
 private function _processData($array)
 {
     foreach ($array as $tableName => $content) {
         foreach ($content as $action => $rows) {
             switch ($action) {
                 case 'insert':
                     foreach ($rows as $data) {
                         $relations = array();
                         if (isset($data['_relations'])) {
                             $relations = $data['_relations'];
                             unset($data['_relations']);
                         }
                         $data = $this->_convertModulesId($data);
                         $newId = $this->_tableManager->insertRow($tableName, $data);
                         if (!empty($relations)) {
                             $this->_relations[] = array('newId' => $newId, 'content' => $relations);
                         }
                     }
                     break;
                 case 'update':
                     foreach ($rows as $data) {
                         if (empty($data['_sqlWhere'])) {
                             $where = null;
                         } else {
                             $where = $data['_sqlWhere'];
                         }
                         unset($data['_sqlWhere']);
                         $data = $this->_convertModulesId($data);
                         $this->_tableManager->updateRows($tableName, $data, $where);
                     }
                     break;
                 case 'delete':
                     foreach ($rows as $code => $where) {
                         if (empty($code)) {
                             $where = null;
                         }
                         $data = $this->_convertModulesId($data);
                         $this->_tableManager->deleteRows($tableName, $where);
                     }
                     break;
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Migrate P5 projects.
  *
  * @return void
  */
 private function _migrateProjects()
 {
     // Project migration
     $projects = $this->_dbOrig->query("SELECT * FROM " . PHPR_DB_PREFIX . "projekte ORDER BY id")->fetchAll();
     $paths = array();
     $paths[self::PROJECT_ROOT] = "/1/";
     $projectsNotMigrated = -1;
     // Multiple inserts
     $dbFields = array('module_id', 'project_id');
     $dbValues = array();
     // As the Projects may have other projects that come later in the list as parents, it may be needed to postpone
     // their migration until next iteration, and so on, because of 'path' field.
     // Note: 'count($projects)' has to be outside the 'for' sentence because that amount varies after each iteration
     $totalProjects = count($projects);
     // Following looping structure in the 99% of the cases is iterated just a few times and then interrupted.
     for ($i = 0; $i < $totalProjects; $i++) {
         if ($projectsNotMigrated == count($projects)) {
             // Migration ended: last iteration hasn't migrated any Project so neither will do it this one.
             // This is supposed to happen when there are no projects left to migrate
             break;
         }
         $projectsNotMigrated = count($projects);
         foreach ($projects as $index => $project) {
             $oldProjectId = $project['ID'];
             if (empty($project['parent'])) {
                 $parentId = isset($this->_groups[$project['gruppe']]) ? $this->_groups[$project['gruppe']] : self::PROJECT_ROOT;
                 if (!isset($paths[$parentId])) {
                     $paths[$parentId] = $paths[self::PROJECT_ROOT] . $parentId . "/";
                 }
             } else {
                 // Has parent project been processed?
                 $oldParentId = $project['parent'];
                 if (isset($this->_projects[$oldParentId])) {
                     // Yes
                     $parentId = $this->_projects[$oldParentId];
                 } else {
                     // No - Continue to the next iteration of the foreach structure, current project has to be
                     // processed later.
                     continue;
                 }
             }
             // Check and repair corrupted dates the way P5 would show them to the user: 2005-06-31 -> 2005-07-01
             $startDate = Cleaner::sanitize('date', $project['anfang']);
             $endDate = Cleaner::sanitize('date', $project['ende']);
             $project['von'] = $this->_processOwner($project['von']);
             $projectId = $this->_tableManager->insertRow('project', array('path' => $paths[$parentId], 'project_id' => $parentId, 'title' => $this->_fix($project['name'], 255), 'notes' => $this->_fix($project['note'], 65500), 'owner_id' => $project['von'], 'start_date' => $startDate, 'end_date' => $endDate, 'priority' => (int) $project['wichtung'], 'current_status' => (int) $project['kategorie'], 'complete_percent' => $project['status'], 'hourly_wage_rate' => $this->_fix($project['stundensatz'], 10), 'budget' => $this->_fix($project['budget'], 10)));
             $this->_projects[$oldProjectId] = $projectId;
             $path = $paths[$parentId] . $projectId . "/";
             $paths[$projectId] = $path;
             // Migrate permissions
             $project['ID'] = $projectId;
             $project['p6ProjectId'] = $parentId;
             $this->_migratePermissions('Project', $project);
             // Add search values
             $words = array($this->_fix($project['name'], 255), $this->_fix($project['note'], 65500));
             $itemId = $project['ID'];
             $this->_addSearchDisplay(1, $itemId, $project['p6ProjectId'], $words[0], $words[1]);
             $this->_addSearchWords(implode(" ", $words), 1, $itemId);
             foreach ($this->_modules as $moduleId) {
                 $dbValues[] = array($moduleId, $projectId);
             }
             // Take out this project from the array
             unset($projects[$index]);
         }
     }
     // Run the multiple inserts
     if (!empty($dbValues)) {
         $this->_tableManager->insertMultipleRows('project_module_permissions', $dbFields, $dbValues);
     }
     // Save data into the session
     // Projects
     $this->_saveSession('migratedProjects', $this->_projects);
 }