예제 #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;
             }
         }
     }
 }
예제 #2
0
 /**
  * Migrate P5 users.
  *
  * @return void
  */
 private function _migrateUsers()
 {
     // User migration
     $query = "SELECT * FROM " . PHPR_DB_PREFIX . "users";
     $users = $this->_dbOrig->query($query)->fetchAll();
     // Just in case
     $this->_users[self::USER_ADMIN] = self::USER_ADMIN;
     // Multiple inserts
     $dbFields = array('id', 'user_id', 'module_id', 'key_value', 'value', 'identifier');
     $dbValues = array();
     $moduleId = $this->_getModuleId('Project');
     foreach ($users as $user) {
         $loginName = $user['loginname'];
         $firstName = $this->_fix($user['vorname'], 255);
         $lastName = $this->_fix($user['nachname'], 255);
         if ($loginName != "root" && $loginName != "test") {
             switch (PHPR_LOGIN_SHORT) {
                 case '2':
                     $username = $user['loginname'];
                     break;
                 case '1':
                     $username = $user['kurz'];
                     break;
                 default:
                     $username = $user['nachname'];
                     break;
             }
             // Set random username for wrong values
             if (empty($username)) {
                 $username = md5(uniqid(rand(), 1));
             }
             if ($user['status'] == 0) {
                 $status = "A";
             } else {
                 $status = 'I';
             }
             $userId = $this->_tableManager->insertRow('user', array('username' => $this->_fix($username), 'firstname' => $firstName, 'lastname' => $lastName, 'status' => $status, 'admin' => 0));
             // Add permission for this user to root project
             $userRightsAdd = array($userId => $this->_accessAdmin);
             $this->_addItemRights($moduleId, self::PROJECT_ROOT, $userRightsAdd);
         } else {
             // Don't migrate 'root' and 'test' users themselves, they are replaced by already inserted 'admin' and
             // 'test' although but its attributes will be migrated indeed.
             if ($loginName == 'root') {
                 $userId = self::USER_ADMIN;
             } elseif ($loginName == 'test') {
                 $userId = self::USER_TEST;
             }
             // Update name fields
             $data = array('firstname' => $firstName, 'lastname' => $lastName);
             $where = sprintf("id = %d", $userId);
             $this->_tableManager->updateRows('user', $data, $where);
         }
         // Migrate password for all users except for P5 'root' and 'test'
         if ($loginName != 'root' && $loginName != 'test') {
             if (defined("PHPR_VERSION") && PHPR_VERSION >= '5.2.1') {
                 $password = $user['pw'];
             } else {
                 $password = md5('phprojektmd5' . $username);
             }
             if ($loginName == 'test') {
                 // Update setting
                 $data = array('value' => $password);
                 $where = sprintf("user_id = %d AND module_id = 0 and key_value = 'password' AND " . "identifier = 'Core'", $userId);
                 $this->_tableManager->updateRows('setting', $data, $where);
             } else {
                 // Prepare setting
                 $dbValues[] = array(null, $userId, 0, 'password', $password, 'Core');
             }
         }
         $oldUserId = $user['ID'];
         $this->_users[$oldUserId] = $userId;
         $this->_userKurz[$user['kurz']] = $userId;
         $this->_timeZone[$userId] = "000";
         $language = 'en';
         @($settings = unserialize($user['settings']));
         if (is_array($settings)) {
             if (isset($settings['timezone'])) {
                 $this->_timeZone[$userId] = $this->_getP6TimeZone($settings['timezone']);
             }
             if (isset($settings['langua'])) {
                 $language = $settings['langua'];
             }
         }
         // Migrate rest of settings
         if ($loginName == 'root' || $loginName == 'test') {
             // Update them
             // Email
             if (is_null($user['email'])) {
                 $user['email'] = '';
             }
             $data = array('value' => $user['email']);
             $where = sprintf("user_id = %d AND module_id = 0 and key_value = 'email' AND identifier = 'Core'", $userId);
             $this->_tableManager->updateRows('setting', $data, $where);
             // Language
             $data = array('value' => $language);
             $where = sprintf("user_id = %d AND module_id = 0 and key_value = 'language' AND identifier = 'Core'", $userId);
             $this->_tableManager->updateRows('setting', $data, $where);
             // Time Zone
             $data = array('value' => $this->_timeZone[$userId]);
             $where = sprintf("user_id = %d AND module_id = 0 and key_value = 'timeZone' AND identifier = 'Core'", $userId);
             $this->_tableManager->updateRows('setting', $data, $where);
         } else {
             // Insert them
             // Email
             if (is_null($user['email'])) {
                 $user['email'] = '';
             }
             $dbValues[] = array(null, $userId, 0, 'email', $user['email'], 'Core');
             // Language
             $dbValues[] = array(null, $userId, 0, 'language', $language, 'Core');
             // Time Zone
             $dbValues[] = array(null, $userId, 0, 'timeZone', $this->_timeZone[$userId], 'Core');
         }
     }
     // Run the multiples insert
     if (!empty($dbValues)) {
         $this->_tableManager->insertMultipleRows('setting', $dbFields, $dbValues);
     }
     // Save data into the session
     // Users
     $this->_saveSession('migratedUsers', $this->_users);
     // UserKurz
     $this->_saveSession('migratedUserKurz', $this->_userKurz);
     // TimeZone
     $this->_saveSession('migratedTimeZone', $this->_timeZone);
 }