本文整理汇总了PHP中Mage_Connect_Package类的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Connect_Package类的具体用法?PHP Mage_Connect_Package怎么用?PHP Mage_Connect_Package使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mage_Connect_Package类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->stepHook('pre');
//Load Magento core
$mageFile = realpath(getcwd() . '/../../app/Mage.php');
if (!@(include_once $mageFile)) {
throw new \Exception('Can\'t find Mage.php. Are you running this from your `.modman` directory?');
} else {
require_once $mageFile;
}
//Boilerplate
umask(0);
\Mage::app();
$output->write('Generating XML... ');
// Generate a package XML file from our template and modman file
$packageXmlFile = $this->_generatePackageXmlFile($input->getOption('package-template-xml-file'), $input->getOption('modman-file'));
$packageXmlFile = getcwd() . '/' . $packageXmlFile;
$output->writeln('<info>Done.</info>');
//Build package
$output->write('Building package... ');
chdir('../../');
$package = new \Mage_Connect_Package($packageXmlFile);
$package->save($input->getOption('output-directory'));
$output->writeln('<info>Done.</info>');
$this->stepHook('post');
}
示例2: doPackage
/**
* Package command callback
* @param string $command
* @param array $options
* @param array $params
* @return void
*/
public function doPackage($command, $options, $params)
{
$this->cleanupParams($params);
if (count($params) < 1) {
return $this->doError($command, "Parameters count should be >= 1");
}
$file = strtolower($params[0]);
$file = realpath($file);
if (!file_exists($file)) {
return $this->doError($command, "File {$params[0]} doesn't exist");
}
try {
$packager = new Mage_Connect_Package($file);
$res = $packager->validate();
if (!$res) {
$this->doError($command, implode("\n", $packager->getErrors()));
return;
}
$packager->save(dirname($file));
$this->ui()->output('Done building package');
} catch (Exception $e) {
$this->doError($command, $e->getMessage());
}
}
示例3: doInstall
/**
* Install action callback
* @param string $command
* @param array $options
* @param array $params
* @return void
*/
public function doInstall($command, $options, $params, $objects = array())
{
$this->cleanupParams($params);
$installFileMode = $command === 'install-file';
try {
$packager = $this->getPackager();
$forceMode = isset($options['force']);
$upgradeAllMode = $command == 'upgrade-all';
$upgradeMode = $command == 'upgrade' || $command == 'upgrade-all';
$noFilesInstall = isset($options['nofiles']);
$withDepsMode = !isset($options['nodeps']);
$ignoreModifiedMode = true || !isset($options['ignorelocalmodification']);
$rest = $this->rest();
$ftp = empty($options['ftp']) ? false : $options['ftp'];
if ($ftp) {
list($cache, $config, $ftpObj) = $packager->getRemoteConf($ftp);
} else {
$config = $this->config();
$cache = $this->getSconfig();
}
if ($installFileMode) {
if (count($params) < 1) {
throw new Exception("Argument should be: filename");
}
$filename = $params[0];
if (!@file_exists($filename)) {
throw new Exception("File '{$filename}' not found");
}
if (!@is_readable($filename)) {
throw new Exception("File '{$filename}' is not readable");
}
$package = new Mage_Connect_Package($filename);
$package->validate();
$errors = $package->getErrors();
if (count($errors)) {
throw new Exception("Package file is invalid\n" . implode("\n", $errors));
}
$pChan = $package->getChannel();
$pName = $package->getName();
$pVer = $package->getVersion();
if (!$cache->isChannel($pChan)) {
throw new Exception("'{$pChan}' is not installed channel");
}
$conflicts = $cache->hasConflicts($pChan, $pName, $pVer);
if (false !== $conflicts) {
$conflicts = implode(", ", $conflicts);
if ($forceMode) {
$this->doError($command, "Package {$pChan}/{$pName} {$pVer} conflicts with: " . $conflicts);
} else {
throw new Exception("Package {$pChan}/{$pName} {$pVer} conflicts with: " . $conflicts);
}
}
$conflicts = $package->checkPhpDependencies();
if (true !== $conflicts) {
$confilcts = implode(",", $conflicts);
$err = "Package {$pChan}/{$pName} {$pVer} depends on PHP extensions: " . $conflicts;
if ($forceMode) {
$this->doError($command, $err);
} else {
throw new Exception($err);
}
}
$conflicts = $package->checkPhpVersion();
if (true !== $conflicts) {
$err = "Package {$pChan}/{$pName} {$pVer}: " . $conflicts;
if ($forceMode) {
$this->doError($command, $err);
} else {
throw new Exception($err);
}
}
if (!$noFilesInstall) {
if ($ftp) {
$packager->processInstallPackageFtp($package, $filename, $config, $ftpObj);
} else {
$packager->processInstallPackage($package, $filename, $config);
}
}
$cache->addPackage($package);
$installedDeps = array();
$installedDepsAssoc = array();
$installedDepsAssoc[] = array('channel' => $pChan, 'name' => $pName, 'version' => $pVer);
$installedDeps[] = array($pChan, $pName, $pVer);
$title = isset($options['title']) ? $options['title'] : "Package installed: ";
$out = array($command => array('data' => $installedDeps, 'assoc' => $installedDepsAssoc, 'title' => $title));
if ($ftp) {
$packager->writeToRemoteCache($cache, $ftpObj);
@unlink($config->getFilename());
}
$this->ui()->output($out);
return $out[$command]['data'];
}
if (!$upgradeAllMode) {
//.........这里部分代码省略.........
示例4: doInstall
/**
* Install action callback
*
* @throws Exception
* @param string $command
* @param array $options
* @param array $params
* @param array $objects
* @return array|null
*/
public function doInstall($command, $options, $params, $objects = array())
{
$this->cleanupParams($params);
$installFileMode = $command === 'install-file';
/** @var $ftpObj Mage_Connect_Ftp */
$ftpObj = null;
$ftp = empty($options['ftp']) ? false : $options['ftp'];
/** @var $packager Mage_Connect_Packager */
$packager = $this->getPackager();
/** @var $cache Mage_Connect_Singleconfig */
/** @var $config Mage_Connect_Config */
if ($ftp) {
list($cache, $config, $ftpObj) = $packager->getRemoteConf($ftp);
} else {
$cache = $this->getSconfig();
$config = $this->config();
}
try {
$forceMode = isset($options['force']);
$upgradeAllMode = $command == 'upgrade-all';
$upgradeMode = $command == 'upgrade' || $command == 'upgrade-all';
$noFilesInstall = isset($options['nofiles']);
$withDepsMode = !isset($options['nodeps']);
$ignoreModifiedMode = true || !isset($options['ignorelocalmodification']);
$clearInstallMode = $command == 'install' && !$forceMode;
$installAll = isset($options['install_all']);
$channelAuth = isset($options['auth']) ? $options['auth'] : array();
$rest = $this->rest();
if (empty($config->magento_root)) {
$config->magento_root = dirname(dirname($_SERVER['SCRIPT_FILENAME']));
}
chdir($config->magento_root);
$dirCache = DIRECTORY_SEPARATOR . $config->downloader_path . DIRECTORY_SEPARATOR . Mage_Connect_Config::DEFAULT_CACHE_PATH;
$dirTmp = DIRECTORY_SEPARATOR . Mage_Connect_Package_Reader::PATH_TO_TEMPORARY_DIRECTORY;
$dirMedia = DIRECTORY_SEPARATOR . 'media';
$isWritable = true;
if ($ftp) {
$cwd = $ftpObj->getcwd();
$ftpObj->mkdirRecursive($cwd . $dirCache, 0777);
$ftpObj->chdir($cwd);
$ftpObj->mkdirRecursive($cwd . $dirTmp, 0777);
$ftpObj->chdir($cwd);
$ftpObj->mkdirRecursive($cwd . $dirMedia, 0777);
$ftpObj->chdir($cwd);
$err = "Please check for sufficient ftp write file permissions.";
} else {
@mkdir($config->magento_root . $dirCache, 0777, true);
@mkdir($config->magento_root . $dirTmp, 0777, true);
@mkdir($config->magento_root . $dirMedia, 0777, true);
$isWritable = is_writable($config->magento_root) && is_writable($config->magento_root . DIRECTORY_SEPARATOR . $config->downloader_path) && is_writable($config->magento_root . $dirCache) && is_writable($config->magento_root . $dirTmp) && is_writable($config->magento_root . $dirMedia);
$err = "Please check for sufficient write file permissions.";
}
$isWritable = $isWritable && is_writable($config->magento_root . $dirMedia) && is_writable($config->magento_root . $dirCache) && is_writable($config->magento_root . $dirTmp);
if (!$isWritable) {
$this->doError($command, $err);
throw new Exception('Your Magento folder does not have sufficient write permissions, which downloader requires.');
}
if (!empty($channelAuth)) {
$rest->getLoader()->setCredentials($channelAuth['username'], $channelAuth['password']);
}
if ($installFileMode) {
if (count($params) < 1) {
throw new Exception("Argument should be: filename");
}
$filename = $params[0];
if (!@file_exists($filename)) {
throw new Exception("File '{$filename}' not found");
}
if (!@is_readable($filename)) {
throw new Exception("File '{$filename}' is not readable");
}
$package = new Mage_Connect_Package($filename);
$package->setConfig($config);
$package->validate();
$errors = $package->getErrors();
if (count($errors)) {
throw new Exception("Package file is invalid\n" . implode("\n", $errors));
}
$pChan = $package->getChannel();
$pName = $package->getName();
$pVer = $package->getVersion();
if (!($cache->isChannelName($pChan) || $cache->isChannelAlias($pChan))) {
throw new Exception("The '{$pChan}' channel is not installed. Please use the MAGE shell " . "script to install the '{$pChan}' channel.");
}
$conflicts = $cache->hasConflicts($pChan, $pName, $pVer);
if (false !== $conflicts) {
$conflicts = implode(", ", $conflicts);
if ($forceMode) {
$this->doError($command, "Package {$pChan}/{$pName} {$pVer} conflicts with: " . $conflicts);
} else {
//.........这里部分代码省略.........
示例5: processInstallPackage
/**
* Package installation to FS
* @param Mage_Connect_Package $package
* @param string $file
* @return void
* @throws Exception
*/
public function processInstallPackage($package, $file, $configObj)
{
$contents = $package->getContents();
$arc = $this->getArchiver();
$target = dirname($file) . DS . $package->getReleaseFilename();
@mkdir($target, 0777, true);
$tar = $arc->unpack($file, $target);
$modeFile = $this->_getFileMode($configObj);
$modeDir = $this->_getDirMode($configObj);
foreach ($contents as $file) {
$fileName = basename($file);
$filePath = dirname($file);
$source = $tar . DS . $file;
$targetPath = rtrim($configObj->magento_root, "\\/");
@mkdir($targetPath . DS . $filePath, $modeDir, true);
$dest = $targetPath . DS . $filePath . DS . $fileName;
if (is_file($source)) {
@copy($source, $dest);
if ($modeFile) {
@chmod($dest, $modeFile);
}
} else {
@mkdir($dest, $modeDir);
}
}
$packageXml = $tar . Mage_Connect_Package_Reader::DEFAULT_NAME_PACKAGE;
if (is_file($packageXml)) {
$destDir = $targetPath . DS . Mage_Connect_Package::PACKAGE_XML_DIR;
$destFile = $package->getReleaseFilename() . '.xml';
$dest = $destDir . DS . $destFile;
@copy($packageXml, $dest);
@chmod($dest, $modeFile);
}
Mage_System_Dirs::rm(array("-r", $target));
}
示例6: processInstallPackage
/**
* Package installation to FS
* @param Mage_Connect_Package $package
* @param string $file
* @return void
* @throws Exception
*/
public function processInstallPackage($package, $file, $configObj)
{
$contents = $package->getContents();
$arc = $this->getArchiver();
$target = dirname($file) . DS . $package->getReleaseFilename();
@mkdir($target, 0777, true);
$mode = $configObj->global_dir_mode;
$tar = $arc->unpack($file, $target);
$modeFile = $configObj->global_file_mode;
$modeDir = $configObj->global_dir_mode;
foreach ($contents as $file) {
$fileName = basename($file);
$filePath = dirname($file);
$source = $tar . DS . $file;
$targetPath = rtrim($configObj->magento_root, "\\/");
@mkdir($targetPath . DS . $filePath, $modeDir, true);
$dest = $targetPath . DS . $filePath . DS . $fileName;
if (is_file($source)) {
@copy($source, $dest);
if ($modeFile) {
@chmod($dest, $modeFile);
}
} else {
@mkdir($dest, $modeDir);
}
}
Mage_System_Dirs::rm(array("-r", $target));
}
示例7: addPackage
/**
* Add package
* @param Mage_Connect_Package $package
* @return void
*/
public function addPackage($package)
{
$channel = $this->chanName($package->getChannel());
$name = $package->getName();
$record = array(self::K_VER => $package->getVersion(), self::K_STATE => $package->getStability(), self::K_XML => $package->getPackageXml(), self::K_NAME => $name, self::K_DEPS => array(), self::K_PACK_DEPS => array());
$this->setPackageRecord($channel, $name, $record);
$this->setPackageDependencies($channel, $name, $package->getDependencyPackages());
$this->save();
}
示例8: doSyncPear
/**
* Synchronize packages installed earlier (by pear installer) with local cache
*
* @param string $command
* @param array $options
* @param array $params
*/
public function doSyncPear($command, $options, $params)
{
$this->cleanupParams($params);
try {
$packager = $this->getPackager();
$cache = null;
$config = null;
$ftpObj = null;
$ftp = empty($options['ftp']) ? false : $options['ftp'];
if ($ftp) {
list($cache, $config, $ftpObj) = $packager->getRemoteConf($ftp);
} else {
$config = $this->config();
$cache = $this->getSconfig();
}
$pkglist = array();
if (!$this->_checkPearData($config)) {
return $pkglist;
}
$pearStorage = $config->magento_root . DS . $config->downloader_path . DS . self::PACKAGE_PEAR_DIR;
$channels = array('.channel.connect.magentocommerce.com_community', '.channel.connect.magentocommerce.com_core');
foreach ($channels as $channel) {
$channelDirectory = $pearStorage . DS . $channel;
if (!file_exists($channelDirectory) || !is_dir($channelDirectory)) {
continue;
}
$dp = opendir($channelDirectory);
if (!$dp) {
continue;
}
while ($ent = readdir($dp)) {
if ($ent[0] == '.' || substr($ent, -4) != '.reg') {
continue;
}
$pkglist[] = array('file' => $ent, 'channel' => $channel);
}
closedir($dp);
}
$package = new Mage_Connect_Package();
foreach ($pkglist as $pkg) {
$pkgFilename = $pearStorage . DS . $pkg['channel'] . DS . $pkg['file'];
if (!file_exists($pkgFilename)) {
continue;
}
$data = file_get_contents($pkgFilename);
$data = unserialize($data);
$package->importDataV1x($data);
$name = $package->getName();
$channel = $package->getChannel();
$version = $package->getVersion();
if (!$cache->isChannel($channel) && $channel == $config->root_channel) {
$cache->addChannel($channel, $config->root_channel_uri);
}
if (!$cache->hasPackage($channel, $name, $version, $version)) {
$cache->addPackage($package);
if ($ftp) {
$localXml = tempnam(sys_get_temp_dir(), 'package');
@file_put_contents($localXml, $package->getPackageXml());
if (is_file($localXml)) {
$ftpDir = $ftpObj->getcwd();
$remoteXmlPath = $ftpDir . '/' . Mage_Connect_Package::PACKAGE_XML_DIR;
$remoteXml = $package->getReleaseFilename() . '.xml';
$ftpObj->mkdirRecursive($remoteXmlPath);
$ftpObj->upload($remoteXml, $localXml, 0777, 0666);
$ftpObj->chdir($ftpDir);
}
} else {
$destDir = rtrim($config->magento_root, "\\/") . DS . Mage_Connect_Package::PACKAGE_XML_DIR;
$destFile = $package->getReleaseFilename() . '.xml';
$dest = $destDir . DS . $destFile;
@mkdir($destDir, 0777, true);
@file_put_contents($dest, $package->getPackageXml());
@chmod($dest, 0666);
}
$this->ui()->output("Successfully added: {$channel}/{$name}-{$version}");
}
}
$config->sync_pear = true;
if ($ftp) {
$packager->writeToRemoteCache($cache, $ftpObj);
@unlink($config->getFilename());
}
} catch (Exception $e) {
$this->doError($command, $e->getMessage());
}
return true;
}
示例9: doSync
/**
* Synchronize manually installed package info with local cache
*
* @param string $command
* @param array $options
* @param array $params
*/
public function doSync($command, $options, $params)
{
$this->cleanupParams($params);
try {
$packager = $this->getPackager();
$ftp = empty($options['ftp']) ? false : $options['ftp'];
if ($ftp) {
list($cache, $config, $ftpObj) = $packager->getRemoteConf($ftp);
} else {
$config = $this->config();
$cache = $this->getSconfig();
}
$packageDir = $config->magento_root . DS . Mage_Connect_Package::PACKAGE_XML_DIR;
if (is_dir($packageDir)) {
$entries = scandir($packageDir);
foreach ((array) $entries as $entry) {
$path = $packageDir . DS . $entry;
$info = pathinfo($path);
if ($entry == '.' || $entry == '..' || is_dir($path) || $info['extension'] != 'xml') {
continue;
}
if (is_readable($path)) {
$data = file_get_contents($path);
if ($data === false) {
continue;
}
$package = new Mage_Connect_Package($data);
$name = $package->getName();
$channel = $package->getChannel();
$version = $package->getVersion();
if (!$cache->hasPackage($channel, $name, $version, $version)) {
$cache->addPackage($package);
$this->ui()->output("Successfully added: {$channel}/{$name}-{$version}");
}
}
}
if ($ftp) {
$packager->writeToRemoteCache($cache, $ftpObj);
}
}
} catch (Exception $e) {
$this->doError($command, $e->getMessage());
}
}
示例10: Mage_Connect_Package
<?php
/**
* Generate modman file from Magento Connect 2.0 package.xml
*
* Usage:
*
* php package2modman.php path/to/package.xml > path/to/modman
*
*/
require_once __DIR__ . "/../www/app/Mage.php";
$package = new Mage_Connect_Package($argv[1]);
$modmanDefinition = array();
foreach ($package->getContents() as $path) {
$path = preg_replace('{^\\./}', '', $path);
$path = preg_replace('{^app/code/(.*?)/(.*?)/(.*?)/(.*)$}', 'app/code/$1/$2/$3', $path);
$path = preg_replace('{^lib/(.*?)/(.*)$}', 'lib/$1', $path);
$path = preg_replace('{^js/(.*?)/(.*?)/(.*)$}', 'js/$1', $path);
$path = preg_replace('{^app/design/(.*?)/(.*?)/default/layout/(.*?)/(.*)$}', 'app/design/$1/$2/default/layout/$3', $path);
$path = preg_replace('{^app/design/(.*?)/(.*?)/default/template/(.*?)/(.*)$}', 'app/design/$1/$2/default/template/$3', $path);
$path = preg_replace('{^skin/(.*?)/(.*?)/default/(.*?)/(.*?)/(.*)$}', 'skin/$1/$2/default/$3/$4', $path);
$modmanDefinition[$path] = $path;
}
foreach ($modmanDefinition as $source => $target) {
printf("%s %s\n", $source, $target);
}