function testdataAction() { $request = new RivetyCore_Request($this->getRequest()); if ($this->getRequest()->isPost()) { $errors = array(); $data_path = $request->data_path; $data_file = $data_path . "/users.dat"; $image_dir = $data_path . "/images"; $users_table = new Users(); $users_roles_table = new UsersRoles(); if($request->has("email_domain")){ $email_domain = $request->email_domain; } else { $email_domain = "nowhere.com"; } if (!file_exists($data_file)) { $errors[] = $this->_T("Data file missing. Check path."); } else { $users = unserialize(file_get_contents($data_file)); if (!is_array($users)) { $errors[] = $this->_T("Data file is corrupt or something."); } } if (count($errors) == 0) { $old_users = $users_table->fetchAll(); // foreach ($old_users as $old_user) { // if ($users_table->getMetaData($old_user->username, "is_test_user") == "true") { // $where = $users_table->getAdapter()->quoteInto("username = ?", $old_user->username); // $users_table->delete($where); // $users_roles_table->delete($where); // } // } $count = 0; foreach ($users as $user) { $tmp_user = array(); foreach ($user as $key => $value) { $tmp_user[$key] = $value; // if ($key != "avatar") { // } } $tmp_user['email'] = strtolower($tmp_user['username'] . "@" . $email_domain); $tmp_user['password'] = "******"; // $destination_path = $users_table->getAvatarPath($user['username']); // $destination_filename = $users_table->getAvatarPath($user['username'], true); // if (!is_dir($destination_path)) { // mkdir($destination_path, 0777, true); // } // if (file_exists($destination_filename)) { // unlink($destination_filename); // } // $source_image = $image_dir."/".$user['avatar']; // copy($source_image, $destination_filename); $role_data = array("username" => $tmp_user['username'],"role_id" => $tmp_user['role_id']); $users_roles_table->insert($role_data); unset($tmp_user['role_id']); $users_table->insert($tmp_user); // $users_table->setMetaData($tmp_user['username'], "is_test_user", "true"); $save_users[] = $user; $count++; } $this->view->success = "User data loaded. Created ".$count." users."; RivetyCore_Registry::set('test_data_path', $request->data_path); $this->view->data_path = RivetyCore_Registry::get('test_data_path'); $this->view->email_domain = $email_domain; } else { $this->view->errors = $errors; $this->view->data_path = Zend_Registry::get('basepath')."/tmp/testdata"; $this->view->email_domain = $request->email_domain; } } else { $this->view->data_path = Zend_Registry::get('basepath')."/tmp/testdata"; $this->view->email_domain = "nowhere.com"; $this->view->notice = $this->_T("Warning: If you are reinstalling the test data, the old test data will be overwritten. Users created outside the test data should not be affected."); } }