svn: /pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/ CLI.php Categories.php REST/Category.php REST/Manager.php

From: Date: Thu, 19 Nov 2009 15:19:08 +0000
Subject: svn: /pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/ CLI.php Categories.php REST/Category.php REST/Manager.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-9035@lists.php.net to get a copy of this message
saltybeagle Thu, 19 Nov 2009 15:19:08 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=291004 Log: Write out c/{category}/packages.xml correctly and ensure existing packages aren't un-categorized. Changed paths: U pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/CLI.php U pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/Categories.php U pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/REST/Category.php U pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/REST/Manager.php Modified: pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/CLI.php =================================================================== --- pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/CLI.php 2009-11-19 15:13:04 UTC (rev 291003) +++ pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/CLI.php 2009-11-19 15:19:08 UTC (rev 291004) @@ -77,6 +77,7 @@ $categories->linkPackageToCategory($args['package'], $args['category']); $category = new REST\Category($this->dir . '/rest', $this->channel->name, 'rest/', $categories); $category->saveAllCategories(); + $category->savePackages($args['category']); $category->savePackagesInfo($args['category']); echo "Added {$args['package']} to {$args['category']} \n"; } Modified: pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/Categories.php =================================================================== --- pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/Categories.php 2009-11-19 15:13:04 UTC (rev 291003) +++ pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/Categories.php 2009-11-19 15:19:08 UTC (rev 291004) @@ -159,12 +159,30 @@ */ public function packagesInCategory($category) { - $ret = array(); + $packages = array(); + $file = $this->_restDir.'c/'.urlencode($category).'/packages.xml'; + if (file_exists($file)) { + $parser = new \pear2\Pyrus\XMLParser; + try { + $content = file_get_contents($file); + $content = $parser->parseString($content); + if (isset($content['l']['p']['_content'])) { + $packages[] = $content['l']['p']['_content']; + } else { + foreach ($content['l']['p'] as $package) { + $packages[] = $package['_content']; + } + } + } catch(\Exception $e) { + // unable to parse, assume empty. + } + } foreach ($this->_packages as $p => $c) { - if ($c === $category) { - $ret[] = $p; + if ($c === $category + && !in_array($p, $packages)) { + $packages[] = $p; } } - return $ret; + return $packages; } } \ No newline at end of file Modified: pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/REST/Category.php =================================================================== --- pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/REST/Category.php 2009-11-19 15:13:04 UTC (rev 291003) +++ pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/REST/Category.php 2009-11-19 15:19:08 UTC (rev 291004) @@ -37,6 +37,7 @@ function save(\pear2\Pyrus\Package $new) { $category = $this->_categories->getPackageCategory($new->name); + $this->savePackages($category); $this->savePackagesInfo($category); $this->saveAllCategories(); } @@ -100,10 +101,29 @@ $xml = $this->_getProlog('c', 'category'); $xml['c']['n'] = $category; $xml['c']['a'] = $alias ? $category : $alias; - $xml['c']['c'] = $this->channel; + $xml['c']['c'] = $this->channel->name; $xml['c']['d'] = $desc; $this->saveCategoryREST(urlencode($category) . '/info.xml', $xml); } + + /** + * Save packages.xml containing a list of all packages within this category + * + * @param string $category Category to save + * + * @return void + */ + function savePackages($category) + { + $packages = ''; + foreach ($this->_categories->packagesInCategory($category) as $package) { + $packages['p'][] = array('attribs' => array('xlink:href' => $this->getPackageRESTLink($package)), + '_content' => $package); + } + $xml = $this->_getProlog('l', 'categorypackages'); + $xml['l'][] = $packages; + $this->saveCategoryREST(urlencode($category) . DIRECTORY_SEPARATOR . 'packages.xml', $xml); + } /** * Save packagesinfo.xml for a category Modified: pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/REST/Manager.php =================================================================== --- pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/REST/Manager.php 2009-11-19 15:13:04 UTC (rev 291003) +++ pear2/sandbox/SimpleChannelServer/trunk/src/SimpleChannelServer/REST/Manager.php 2009-11-19 15:19:08 UTC (rev 291004) @@ -97,14 +97,12 @@ $this->chan . ' channel, and package is in ' . $new->channel . ' channel'); } - $category = new Category($this->rest, $this->channel, - $this->uri); - $package = new Package($this->rest, $this->channel, - $this->uri); - $maintainer = new Maintainer($this->rest, $this->channel, - $this->uri); - $release = new Release($this->rest, $this->channel, - $this->uri); + + $category = new Category($this->rest, $this->channel, $this->uri); + $package = new Package($this->rest, $this->channel, $this->uri); + $maintainer = new Maintainer($this->rest, $this->channel, $this->uri); + $release = new Release($this->rest, $this->channel, $this->uri); + $maintainer->erase($new, $deleteorphaned); $package->erase($new); $release->erase($new);

« previous php.pear.core (#9035) next »