/** * Regression test for issue #15263 * Content object name/url of imported content classes aren't generated correctly * * @url http://issues.ez.no/15263 * * @outline * 1) Expire and force generation of class attribute cache * 2) Load a test package * 3) Install the package * 4) Publish an object of the imported class * 5) The object name / url alias shouldn't be the expected one **/ public function testIssue15263() { $adminUser = eZUser::fetchByName('admin'); $previousUser = eZUser::currentUser(); eZUser::setCurrentlyLoggedInUser($adminUser, $adminUser->attribute('contentobject_id')); // 1) Expire and force generation of class attribute cache $handler = eZExpiryHandler::instance(); $handler->setTimestamp('class-identifier-cache', time() - 1); $handler->store(); eZContentClassAttribute::classAttributeIdentifierByID(1); // 1) Load a test package $packageName = 'ezpackage_regression_testIssue15223.ezpkg'; $packageFilename = dirname(__FILE__) . DIRECTORY_SEPARATOR . $packageName; $packageImportTried = false; while (!$packageImportTried) { $package = eZPackage::import($packageFilename, $packageName); if (!$package instanceof eZPackage) { if ($package === eZPackage::STATUS_ALREADY_EXISTS) { $packageToRemove = eZPackage::fetch($packageName); $packageToRemove->remove(); } else { self::fail("An error occured loading the package '{$packageFilename}'"); } } $packageImportTried = true; } // 2) Install the package $installParameters = array('site_access_map' => array('*' => false), 'top_nodes_map' => array('*' => 2), 'design_map' => array('*' => false), 'restore_dates' => true, 'user_id' => $adminUser->attribute('contentobject_id'), 'non-interactive' => true, 'language_map' => $package->defaultLanguageMap()); $result = $package->install($installParameters); // 3) Publish an object of the imported class $object = new ezpObject('test_issue_15523', 2, $adminUser->attribute('contentobject_id'), 1); $object->myname = __METHOD__; $object->myothername = __METHOD__; $publishedObjectID = $object->publish(); unset($object); // 4) Test data from the publish object $publishedNodeArray = eZContentObjectTreeNode::fetchByContentObjectID($publishedObjectID); if (count($publishedNodeArray) != 1) { $this->fail("An error occured fetching node for object #{$publishedObjectID}"); } $publishedNode = $publishedNodeArray[0]; if (!$publishedNode instanceof eZContentObjectTreeNode) { $this->fail("An error occured fetching node for object #{$publishedObjectID}"); } else { $this->assertEquals("eZPackageRegression::testIssue15263", $publishedNode->attribute('name')); $this->assertEquals("eZPackageRegression-testIssue15263", $publishedNode->attribute('url_alias')); } // Remove the installed package & restore the logged in user $package->remove(); eZUser::setCurrentlyLoggedInUser($previousUser, $previousUser->attribute('contentobject_id')); }
function downloadPackages($packageList, $packageURL, $packageDir, $packageRepository) { global $cli; showMessage2("Configuring..."); if (!is_array($packageList) || count($packageList) == 0) { showError("Package list is empty. Aborting..."); } // 1. check if packages specified in $packageList exist in $packageRepository(means already downloaded and imported). // if yes - ask user to do download or not. If not - go out foreach (array_keys($packageList) as $k) { $packageName = $packageList[$k]; $package = eZPackage::fetch($packageName); if (is_object($package)) { global $autoMode; if ($autoMode == 'on') { $action = 'y'; } else { $action = getUserInput("Package '{$packageName}' already imported. Import it anyway? [y/n]: "); } if (strpos($action, 'n') === 0) { unset($packageList[$k]); } else { eZDir::recursiveDelete(eZPackage::repositoryPath() . "/{$packageRepository}/{$packageName}"); } } } if (count($packageList) == 0) { // all packages are imported. return true; } // 2. check $packgesList exists in $packageDir(means packages downloaded but not imported) // if yes - ask user to import or not. If not - go out if (!checkDir($packageDir)) { return false; } $downloadPackageList = array(); foreach ($packageList as $packageName) { if (file_exists("{$packageDir}/{$packageName}.ezpkg")) { global $autoMode; if ($autoMode == 'on') { $action = 'y'; } else { $action = getUserInput("Package '{$packageName}' already downloaded. Download it anyway? [y/n]: "); } if (strpos($action, 'n') === 0) { continue; } } $downloadPackageList[] = $packageName; } // // download // showMessage2("Downloading..."); if (count($downloadPackageList) > 0) { // TODO: using 'eZStepSiteTypes' is hack. // need to exclude 'downloadFile' from that class. $tpl = false; $http = false; $ini = false; $persistenceList = false; $downloader = new eZStepSiteTypes($tpl, $http, $ini, $persistenceList); foreach ($downloadPackageList as $packageName) { showMessage("{$packageName}"); $archiveName = $downloader->downloadFile("{$packageURL}/{$packageName}.ezpkg", $packageDir); if ($archiveName === false) { showError("download error - " . $downloader->ErrorMsg); } } } // // import // showMessage2("Importing..."); foreach ($packageList as $packageName) { showMessage("{$packageName}"); $package = eZPackage::import("{$packageDir}/{$packageName}.ezpkg", $packageName, false, $packageRepository); if (!is_object($package)) { showError("Faild to import '{$packageName}' package: err = {$package}"); } } return true; }
* @version 2013.11 * @package kernel */ $module = $Params['Module']; if (!eZPackage::canUsePolicyFunction('import')) { return $module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel'); } $package = false; $installElements = false; $errorList = array(); if ($module->isCurrentAction('UploadPackage')) { if (eZHTTPFile::canFetch('PackageBinaryFile')) { $file = eZHTTPFile::fetch('PackageBinaryFile'); if ($file) { $packageFilename = $file->attribute('filename'); $package = eZPackage::import($packageFilename, $packageName); if ($package instanceof eZPackage) { if ($package->attribute('install_type') != 'install' or !$package->attribute('can_install')) { return $module->redirectToView('view', array('full', $package->attribute('name'))); } else { if ($package->attribute('install_type') == 'install') { return $module->redirectToView('install', array($package->attribute('name'))); } } } else { if ($package == eZPackage::STATUS_ALREADY_EXISTS) { $errorList[] = array('description' => ezpI18n::tr('kernel/package', 'Package %packagename already exists, cannot import the package', false, array('%packagename' => $packageName))); } else { if ($package == eZPackage::STATUS_INVALID_NAME) { $errorList[] = array('description' => ezpI18n::tr('kernel/package', 'The package name %packagename is invalid, cannot import the package', false, array('%packagename' => $packageName))); } else {
/** * Upload local package. * * \private */ function uploadPackage() { if (!eZHTTPFile::canFetch('PackageBinaryFile')) { $this->ErrorMsg = ezpI18n::tr('design/standard/setup/init', 'No package selected for upload') . '.'; return; } $file = eZHTTPFile::fetch('PackageBinaryFile'); if (!$file) { $this->ErrorMsg = ezpI18n::tr('design/standard/setup/init', 'Failed fetching upload package file'); return; } $packageFilename = $file->attribute('filename'); $packageName = $file->attribute('original_filename'); if (preg_match("#^(.+)-[0-9](\\.[0-9]+)-[0-9].ezpkg\$#", $packageName, $matches)) { $packageName = $matches[1]; } $packageName = preg_replace(array("#[^a-zA-Z0-9]+#", "#_+#", "#(^_)|(_\$)#"), array('_', '_', ''), $packageName); $package = eZPackage::import($packageFilename, $packageName, false); if (is_object($package)) { // package successfully imported return; } elseif ($package == eZPackage::STATUS_ALREADY_EXISTS) { eZDebug::writeWarning("Package '{$packageName}' already exists."); } else { $this->ErrorMsg = ezpI18n::tr('design/standard/setup/init', 'Uploaded file is not an eZ Publish package'); } }
function importPackage() { $surveyINI = eZINI::instance('ezsurvey.ini'); $packageName = $surveyINI->variable('PackageSettings', 'PackageName'); $packagePath = $surveyINI->variable('PackageSettings', 'PackagePath'); $fileName = $surveyINI->variable('PackageSettings', 'PackageFileName'); $path = eZExtension::baseDirectory() . '/' . $packagePath . '/'; $file = $path . $fileName; if (file_exists($file)) { $package = eZPackage::import($file, $packageName); if (is_object($package)) { $status = $this->installPackage($package); } else { if ($package == eZPackage::STATUS_ALREADY_EXISTS) { $package = eZPackage::fetch($packageName); if (is_object($package)) { $status = $this->installPackage($package); } else { eZDebug::writeError("Could not fetch package: {$packageName}", 'eZSurveyWizard::importPackage'); } } else { eZDebug::writeError("Uploaded file is not an eZ Publish package", 'eZSurveyWizard::importPackage'); } } } else { eZDebug::writeWarning('File "' . $file . '" does not exist', 'eZSurveyWizard::importPackage'); } }
case 'state': $package->setAttribute($commandItem['attribute'], $commandItem['attribute-value']); $cli->output("Attribute " . $cli->style('symbol') . $commandItem['attribute'] . $cli->style('emphasize-end') . " was set to " . $cli->style('symbol') . $commandItem['attribute-value'] . $cli->style('emphasize-end')); break; } $package->store(); } else { $cli->output("package " . $commandItem['name'] . " is not in repository"); } } } else { if ($command == 'import') { $packageFile = $commandItem['name']; if ($packageFile && file_exists($packageFile)) { $packageFile = realpath($packageFile); $package = eZPackage::import($packageFile, $packageName, true, $repositoryID); if ($package instanceof eZPackage) { $cli->output("Package " . $cli->stylize('emphasize', $packageName) . " sucessfully imported"); } else { if ($package == eZPackage::STATUS_ALREADY_EXISTS) { $cli->error("Could not import package " . $cli->stylize('emphasize', $packageName) . ", it already exists"); } else { if ($package == eZPackage::STATUS_INVALID_NAME) { $cli->error("Could not import package " . $cli->stylize('emphasize', $packageName) . ", its name is invalid"); } else { $cli->error("Could not import package " . $packageFile . ", invalid package file"); } } } } else { $cli->error("Could not import package " . $packageFile . ", file was not found");