Commit: 4240cace6664d11040ed6135d584fa80b95f2c9a
Author: gwoo | Date: 2010-01-25 09:31:51 -0800
diff --git a/controllers/ServerController.php b/controllers/ServerController.php
index 62cf5e5..34374ed 100644
--- a/controllers/ServerController.php
+++ b/controllers/ServerController.php
@@ -30,30 +30,22 @@ class ServerController extends \lithium\action\Controller {
$file = Repo::create($this->request->data['phar']);
if ($file->save()) {
- $archive = new Phar($file->getPathname());
- $name = $file->getBasename('.gz');
- $name = basename($name, '.phar');
- $saved = $file->getPath() . '/' . $name;
-
- if ($archive->extractTo($saved)) {
- $formula = Formula::create(array(
- 'name' => "{$name}.json", 'type' => 'application/json',
- 'tmp_name' => "{$saved}/config/{$name}.json"
- ));
- if ($formula->save()) {
- $folder = Repo::create(array('name' => $name));
- $folder->delete();
- $plugin = Plugin::create(json_decode($formula->contents(), true));
- if ($plugin->save()) {
- return $this->render(
- array('json' => $plugin->data(), 'status' => 201)
- );
- }
- $errors = $plugin->errors();
- }
- if (!$errors) {
- $errors = $formula->errors();
+ $name = $file->getBasename('.phar.gz');
+ $formula = Formula::create(array(
+ 'name' => "{$name}.json", 'type' => 'application/json',
+ 'tmp_name' => "phar://". $file->getPathname() . "/config/{$name}.json"
+ ));
+ if ($formula->save()) {
+ $plugin = Plugin::create(json_decode($formula->contents(), true));
+ if ($plugin->save()) {
+ return $this->render(
+ array('json' => $plugin->data(), 'status' => 201)
+ );
}
+ $errors = $plugin->errors();
+ }
+ if (!$errors) {
+ $errors = $formula->errors();
}
}
if (!$errors) {
diff --git a/tests/cases/controllers/ServerControllerTest.php b/tests/cases/controllers/ServerControllerTest.php
index f252591..b3b2058 100644
--- a/tests/cases/controllers/ServerControllerTest.php
+++ b/tests/cases/controllers/ServerControllerTest.php
@@ -43,8 +43,8 @@ class ServerControllerTest extends \lithium\test\Unit {
public function testReceive() {
$this->request->data['phar'] = array(
- 'name' => 'li3_example.phar', 'type' => 'application/phar',
- 'tmp_name' => $this->_fixturesPath . '/fixtures/plugins/li3_example.phar',
+ 'name' => 'li3_example.phar.gz', 'type' => 'application/phar',
+ 'tmp_name' => $this->_fixturesPath . '/fixtures/plugins/li3_example.phar.gz',
);
$this->server->receive();
@@ -53,7 +53,7 @@ class ServerControllerTest extends \lithium\test\Unit {
$expected = 'li3_example';
$this->assertEqual($expected, $result->name);
- $file = LITHIUM_APP_PATH . '/resources/tmp/tests/repos/li3_example.phar';
+ $file = LITHIUM_APP_PATH . '/resources/tmp/tests/repos/li3_example.phar.gz';
$result = file_exists($file);
$this->assertTrue($result);
diff --git a/tests/cases/models/RepoTest.php b/tests/cases/models/RepoTest.php
index 4d35879..3a4c97a 100644
--- a/tests/cases/models/RepoTest.php
+++ b/tests/cases/models/RepoTest.php
@@ -21,19 +21,19 @@ class RepoTest extends \lithium\test\Unit {
public function testSaveAndFind() {
Repo::meta('connection', 'test_resources');
$repo = Repo::create(array(
- 'name' => 'li3_example.phar', 'type' => 'application/phar',
- 'tmp_name' => $this->_fixturesPath . '/fixtures/plugins/li3_example.phar',
+ 'name' => 'li3_example.phar.gz', 'type' => 'application/phar',
+ 'tmp_name' => $this->_fixturesPath . '/fixtures/plugins/li3_example.phar.gz',
));
$result = $repo->save();
$this->assertTrue($result);
- $file = LITHIUM_APP_PATH . '/resources/tmp/tests/repos/li3_example.phar';
+ $file = LITHIUM_APP_PATH . '/resources/tmp/tests/repos/li3_example.phar.gz';
$result = file_exists($file);
$this->assertTrue($result);
$repo = Repo::find('all');
- $expected = 'li3_example.phar';
+ $expected = 'li3_example.phar.gz';
$result = $repo->current()->getFilename();
$this->assertEqual($expected, $result);
}
diff --git a/tests/fixtures/plugins/li3_example.phar b/tests/fixtures/plugins/li3_example.phar
deleted file mode 100644
index 8c0904e..0000000
Binary files a/tests/fixtures/plugins/li3_example.phar and /dev/null differ
diff --git a/tests/fixtures/plugins/li3_example.phar.gz b/tests/fixtures/plugins/li3_example.phar.gz
new file mode 100644
index 0000000..53d90a0
Binary files /dev/null and b/tests/fixtures/plugins/li3_example.phar.gz differ
diff --git a/tests/fixtures/plugins/li3_example/config/li3_example.json b/tests/fixtures/plugins/li3_example/config/li3_example.json
index eb70f02..6f73d67 100644
--- a/tests/fixtures/plugins/li3_example/config/li3_example.json
+++ b/tests/fixtures/plugins/li3_example/config/li3_example.json
@@ -7,7 +7,7 @@
],
"sources": {
"git": "git://rad-dev.org/li3_example.git",
- "phar": "http://downloads.rad-dev.org/li3_example.phar"
+ "phar": "http://downloads.rad-dev.org/li3_example.phar.gz"
},
"requires": {
"li3_lab": { "version": ">= 1.0" }
diff --git a/tests/mocks/extensions/command/MockService.php b/tests/mocks/extensions/command/MockService.php
index 182bdc3..95ea713 100644
--- a/tests/mocks/extensions/command/MockService.php
+++ b/tests/mocks/extensions/command/MockService.php
@@ -53,7 +53,7 @@ class MockService extends \lithium\http\Service {
'created' => '2009-11-30', 'updated' => '2009-11-30',
'rating' => '9.9', 'downloads' => '1000',
'sources' => array(
- 'phar' => dirname(dirname(dirname(__DIR__))) . '/fixtures/plugins/li3_example.phar'
+ 'phar' => dirname(dirname(dirname(__DIR__))) . '/fixtures/plugins/li3_example.phar.gz'
),
'requires' => array(
'li3_lab' => array('version' => '<=1.0')