public function testInstallPluginWithBrokenManager()
    {
        // インストールするプラグインを作成する
        $tmpname = "dummy" . sha1(mt_rand());
        $config = array();
        $config['name'] = $tmpname;
        $config['code'] = $tmpname;
        $config['version'] = $tmpname;
        $tmpdir = $this->createTempDir();
        $tmpfile = $tmpdir . '/plugin.tar';
        $tar = new \PharData($tmpfile);
        $tar->addFromString('config.yml', Yaml::dump($config));
        $dummyManager = <<<'EOD'
<?php
namespace Plugin\@@@@ ;

use Eccube\Plugin\AbstractPluginManager;
class PluginManager extends AbstractPluginManager
{
    public function install($plugin,$app)
    {
        throw new \Exception('hoge',1);
    }

}

EOD;
        $dummyManager = str_replace('@@@@', $tmpname, $dummyManager);
        // イベントクラス名はランダムなのでヒアドキュメントの@@@@部分を置換
        $tar->addFromString("PluginManager.php", $dummyManager);
        $service = $this->app['eccube.service.plugin'];
        try {
            $this->assertTrue($service->install($tmpfile));
            $this->fail("BrokenManager dont throw exception.");
        } catch (\Exception $e) {
        }
        // インストーラで例外発生時にテーブルやファイスシステム上にゴミが残らないか
        $this->assertFileNotExists(__DIR__ . "/../../../../app/Plugin/{$tmpname}");
        // XXX PHPUnit によってロールバックが遅延してしまうので, 検証できないが, 消えているはず
        $this->assertFalse((bool) ($plugin = $this->app['eccube.repository.plugin']->findOneBy(array('name' => $tmpname))));
    }
Example #2
0
 /**
  * @param $content
  * @param $name
  * @param  string          $directoryInArchive
  * @return mixed
  * @throws \ErrorException
  *
  * This method creates a file in the archive with its content
  */
 public function addFileFromString($content, $name, $directoryInArchive = "/")
 {
     if (empty($name) || !is_scalar($name)) {
         throw new \ErrorException($this->translator->trans("The file name must be valid"));
     }
     $directoryInArchive = $this->formatDirectoryPath($directoryInArchive);
     if (!empty($directoryInArchive)) {
         $name = $this->formatFilePath($directoryInArchive . $name);
     }
     try {
         $this->tar->addFromString($name, $content);
     } catch (\Exception $e) {
         throw new \ErrorException($this->translator->trans("Error while writing the file into the archive, error message: %errmes", ["%errmes" => $e->getMessage()]));
     }
 }
Example #3
0
 /**
  * ファイルアップロードからリリース
  * @param string $package_name パッケージ名
  **/
 public function package_release_by_upload($package_name)
 {
     $package = C(OpenpearPackage)->find_get(Q::eq('name', $package_name));
     $package->permission($this->user());
     if ($this->is_post() && $this->is_files('package_file') && $this->verify()) {
         try {
             $package_file = $this->in_files('package_file');
             $package_file->generate(work_path('upload/' . $package_name . '-' . date('YmdHis') . '.tgz'));
             if ($package_xml = simplexml_load_file(sprintf('phar://%s/package.xml', $package_file->fullname()))) {
                 if ($package_xml->name != $package->name()) {
                     throw new OpenpearException(Gettext::trans('incorrect package name'));
                 }
                 if ($package_xml->channel != OpenpearConfig::pear_domain('openpear.org')) {
                     $package_xml->channel = OpenpearConfig::pear_domain('openpear.org');
                     $pd = new PharData($package_file->fullname());
                     $pd->addFromString('package.xml', $package_xml->asXML());
                     unset($pd);
                 }
                 $upload_queue = new stdClass();
                 $upload_queue->package_id = $package->id();
                 $upload_queue->package_file = $package_file->fullname();
                 $upload_queue->maintainer_id = $this->user()->id();
                 $queue = new OpenpearQueue('type=upload_release');
                 $queue->data(serialize($upload_queue));
                 $queue->save();
                 $message = new OpenpearMessage('type=system_notice,mail=false');
                 $message->maintainer_to_id($this->user()->id());
                 $message->subject(trans('リリースキューに追加されました'));
                 $message->description(trans('{1}のリリースを受け付けました。リリースの完了後,メールでお知らせします。', $package->name()));
                 $message->save();
                 $this->redirect_by_map('dashboard');
             }
         } catch (Exception $e) {
             Log::debug($e);
             Exceptions::add($e);
         }
     }
     $this->vars('package', $package);
     $this->vars('package_id', $package->id());
 }
Example #4
0
<?php

$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar';
$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.tar';
$phar = new PharData($fname);
$phar->addEmptyDir('blah/');
$phar->addFromString('test/', '');
copy($fname, $fname2);
$phar = new PharData($fname2);
var_dump($phar['blah']->isDir(), $phar['test']->isDir());
?>
===DONE===
<?php 
error_reporting(0);
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar');
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.tar');
__halt_compiler();
?>
     mkdirs("{$mRoot}/template");
     if ($m['application']['setting']) {
         f_write("{$mRoot}/template/setting.html", "{template 'common/header'}\r\n这里定义页面内容\r\n{template 'common/footer'}");
     }
     if ($m['icon']) {
         file_move($m['icon'], "{$mRoot}/icon.jpg");
     }
     if ($m['preview']) {
         file_move($m['preview'], "{$mRoot}/preview.jpg");
     }
     message("生成成功. 请访问 {$mRoot} 继续实现你的模块.", 'refresh');
 }
 if ($_GPC['method'] == 'download') {
     $fname = IA_ROOT . "/data/tmp.tar";
     $phar = new PharData($fname);
     $phar->addFromString('/manifest.xml', $manifest);
     if ($mDefine) {
         $phar->addFromString('/module.php', $mDefine);
     }
     if ($pDefine) {
         $phar->addFromString('/processor.php', $pDefine);
     }
     if ($rDefine) {
         $phar->addFromString('/receiver.php', $rDefine);
     }
     if ($sDefine) {
         $phar->addFromString('/site.php', $sDefine);
     }
     $phar->addEmptyDir('/template');
     if ($m['application']['setting']) {
         $phar->addFromString("/template/setting.html", "{template 'common/header'}\r\n这里定义页面内容\r\n{template 'common/footer'}");
Example #6
0
 public function testInstallPluginWithConst()
 {
     // インストールするプラグインを作成する
     $tmpname = "dummy" . sha1(mt_rand());
     $config = array();
     $config['name'] = $tmpname . "_name";
     $config['code'] = $tmpname;
     $config['version'] = $tmpname . "_version";
     $config['const']['A'] = 'A';
     $config['const']['C'] = 1;
     $tmpdir = $this->createTempDir();
     $tmpfile = $tmpdir . '/plugin.tar';
     $tar = new \PharData($tmpfile);
     $tar->addFromString('config.yml', Yaml::dump($config));
     $service = $this->app['eccube.service.plugin'];
     // インストールできるか
     $this->assertTrue($service->install($tmpfile));
     $this->assertTrue((bool) ($plugin = $this->app['eccube.repository.plugin']->findOneBy(array('code' => $tmpname))));
     // インストール後disable状態でもconstがロードされているか
     $config = $this->app['config'];
     $config[$tmpname]['const']['A'] = null;
     $config[$tmpname]['const']['C'] = null;
     // const が存在しないのを確認後, 再ロード
     $this->assertFalse(isset($this->app['config'][$tmpname]['const']['A']));
     $this->assertFalse(isset($this->app['config'][$tmpname]['const']['C']));
     $this->app->initializePlugin();
     $this->app->boot();
     $this->assertEquals('A', $this->app['config'][$tmpname]['const']['A']);
     $this->assertEquals('1', $this->app['config'][$tmpname]['const']['C']);
     // アンインストールできるか
     $this->assertTrue($service->uninstall($plugin));
 }
Example #7
0
 /**
  * Create list of archive file hashes and add it to the pack
  *
  * @param \PharData $phar     PHAR archive
  * @param \Iterator $iterator Directory iterator
  *
  * @return void
  */
 protected static function addPackHash(\PharData $phar, \Iterator $iterator)
 {
     $data = array();
     foreach ($iterator as $filePath => $fileInfo) {
         $data[\Includes\Utils\FileManager::getRelativePath($filePath, LC_DIR_ROOT)] = \Includes\Utils\FileManager::getHash($filePath);
     }
     $phar->addFromString('.hash', json_encode($data));
 }
 /**
  * get file content from id
  * @NoCSRFRequired
  * @PublicPage
  */
 public function downloadSensorML($uuid)
 {
     $systems = $this->systemMapper->getByUuid($uuid);
     if ($systems !== null) {
         $fileIds = array();
         $resultFiles = new \PharData(sys_get_temp_dir() . "/{$uuid}.zip");
         foreach ($systems as $system) {
             $fileId = $system->getFileId();
             if (!in_array($fileId, $fileIds)) {
                 $fileIds[] = $fileId;
                 $cacheInfo = FileCacheDao::getCacheInfo($fileId);
                 if ($cacheInfo !== null) {
                     $fileInfo = FileCacheDao::getFileInfo($cacheInfo['storage'], $cacheInfo['path'], $system->getPharPath());
                     $content = FileCacheDao::getContentByUrn($fileInfo['urn']);
                     $resultFiles->addFromString($uuid . "_" . $fileId . ".xml", $content);
                 }
             }
         }
         $fullPath = $resultFiles->getPath();
         if ($fd = fopen($fullPath, "r")) {
             $path_parts = pathinfo($fullPath);
             header("Content-type: application/octet-stream");
             header("Content-Disposition: filename=\"" . $path_parts["basename"] . "\"");
             while (!feof($fd)) {
                 $buffer = fread($fd, 2048);
                 echo $buffer;
             }
         }
         fclose($fd);
     }
     return new NotFoundResponse();
 }
Example #9
0
 /**
  * プラグイン設定ファイルキャッシュの検証
  */
 public function testPluginConfigCache()
 {
     $this->app['debug'] = false;
     $pluginConfigCache = $this->app['config']['plugin_temp_realdir'] . '/config_cache.php';
     // 事前にキャッシュを削除しておく
     if (file_exists($pluginConfigCache)) {
         unlink($pluginConfigCache);
     }
     // インストールするプラグインを作成する
     $tmpname = "dummy" . sha1(mt_rand());
     $config = array();
     $config['name'] = $tmpname . "_name";
     $config['code'] = $tmpname;
     $config['version'] = $tmpname . "_version";
     $config['const']['A'] = 'A';
     $config['const']['C'] = 1;
     $event = array('eccube.event.app.request' => array(0 => array(0 => 'onAppRequest', 1 => 'NORMAL')));
     $tmpdir = $this->createTempDir();
     $tmpfile = $tmpdir . '/plugin.tar';
     $tar = new \PharData($tmpfile);
     $tar->addFromString('config.yml', Yaml::dump($config));
     $tar->addFromString('event.yml', Yaml::dump($event));
     $service = $this->app['eccube.service.plugin'];
     // インストールできるか
     $this->assertTrue($service->install($tmpfile));
     $this->assertTrue((bool) ($plugin = $this->app['eccube.repository.plugin']->findOneBy(array('code' => $tmpname))));
     $this->expected = $pluginConfigCache;
     $this->actual = $this->app->getPluginConfigCacheFile();
     $this->verify('キャッシュファイル名が一致するか');
     $pluginConfigs = $this->app->parsePluginConfigs();
     $this->assertTrue(array_key_exists($tmpname, $pluginConfigs));
     $this->expected = $config;
     $this->actual = $pluginConfigs[$tmpname]['config'];
     $this->verify('parsePluginConfigs の結果が一致するか');
     $this->assertTrue(false !== $this->app->writePluginConfigCache(), 'キャッシュファイルが書き込まれるか');
     $this->assertTrue(file_exists($pluginConfigCache), 'キャッシュファイルが存在するか');
     $this->assertTrue($this->app->removePluginConfigCache(), 'キャッシュファイルを削除できるか');
     $this->assertFalse(file_exists($pluginConfigCache), 'キャッシュファイルが削除されているか');
     $pluginConfigs = $this->app->getPluginConfigAll();
     $this->assertTrue(file_exists($pluginConfigCache), 'キャッシュファイルが再生成されているか');
     $this->expected = $config;
     $this->actual = $pluginConfigs[$tmpname]['config'];
     $this->verify('getPluginConfigAll の結果が一致するか');
     // インストール後disable状態でもconstがロードされているか
     $config = $this->app['config'];
     $config[$tmpname]['const']['A'] = null;
     $config[$tmpname]['const']['C'] = null;
     // const が存在しないのを確認後, 再ロード
     $this->assertFalse(isset($this->app['config'][$tmpname]['const']['A']));
     $this->assertFalse(isset($this->app['config'][$tmpname]['const']['C']));
     $this->app->initPluginEventDispatcher();
     $this->app->loadPlugin();
     $this->app->boot();
     $this->assertEquals('A', $this->app['config'][$tmpname]['const']['A']);
     $this->assertEquals('1', $this->app['config'][$tmpname]['const']['C']);
     // アンインストールできるか
     $this->assertTrue($service->uninstall($plugin));
     $pluginConfigs = $this->app->getPluginConfigAll();
     $this->assertFalse(array_key_exists($tmpname, $pluginConfigs), 'キャッシュからプラグインが削除されているか');
 }
Example #10
0
    public function testInstallPluginWithManager()
    {
        #self::markTestSkipped();
        // インストールするプラグインを作成する
        $tmpname = "dummy" . sha1(mt_rand());
        $config = array();
        $config['name'] = $tmpname;
        $config['code'] = $tmpname;
        $config['version'] = $tmpname;
        $tmpdir = $this->createTempDir();
        $tmpfile = $tmpdir . '/plugin.tar';
        $tar = new \PharData($tmpfile);
        $tar->addFromString('config.yml', Yaml::dump($config));
        $dummyManager = <<<'EOD'
<?php
namespace Plugin\@@@@ ;

use Eccube\Plugin\AbstractPluginManager;
class PluginManager extends AbstractPluginManager
{
    public function install($plugin,$app)
    {
        echo "Installed";
    }

    public function uninstall($config,$app)
    {
        echo "Uninstalled";
    }

    public function enable($config,$app)
    {
        echo "Enabled";
    }

    public function disable($config,$app)
    {
        echo "Disabled";
    }

    public function update($config,$app)
    {
        echo "Updated";
    }
}

EOD;
        $dummyManager = str_replace('@@@@', $tmpname, $dummyManager);
        // イベントクラス名はランダムなのでヒアドキュメントの@@@@部分を置換
        $tar->addFromString("PluginManager.php", $dummyManager);
        $service = $this->app['eccube.service.plugin'];
        // インストールできるか、インストーラが呼ばれるか
        ob_start();
        $this->assertTrue($service->install($tmpfile));
        $this->assertRegexp('/InstalledEnabled/', ob_get_contents());
        ob_end_clean();
        $this->assertFileExists(__DIR__ . "/../../../../app/Plugin/{$tmpname}/PluginManager.php");
        $this->assertTrue((bool) ($plugin = $this->app['eccube.repository.plugin']->findOneBy(array('name' => $tmpname))));
        ob_start();
        $service->enable($plugin);
        $this->assertRegexp('/Enabled/', ob_get_contents());
        ob_end_clean();
        ob_start();
        $service->disable($plugin);
        $this->assertRegexp('/Disabled/', ob_get_contents());
        ob_end_clean();
        // アンインストールできるか、アンインストーラが呼ばれるか
        ob_start();
        $service->disable($plugin);
        $this->assertTrue($service->uninstall($plugin));
        $this->assertRegexp('/DisabledUninstalled/', ob_get_contents());
        ob_end_clean();
    }