【问题标题】:Symfony hack - Executing shell script to rewrite yaml filesSymfony hack - 执行 shell 脚本重写 yaml 文件
【发布时间】:2018-08-06 07:21:32
【问题描述】:

我正在使用 akeneo pim,它使用 symfony 3.4 来解决一些客户的需求。所以这是我第一次使用 symfony,我遇到了一些问题。我需要做的是创建用户界面,用户可以在其中为主菜单添加自己的翻译。这些翻译来自 /translation/jsmessages.en.yml 配置文件。所以我创建了一个包,更改了 yaml 文件,一切都差不多完成了。但是现在当我更改 yaml 文件时,我需要清除缓存、转储翻译、运行 webpack,否则菜单文本更改将不可见。所以我想创建shell脚本来做到这一点。像这样的:

public function indexAction()
{
    (new YmlReader())->readYmlFile();

    exec('rm -rf ./web/bundles/* ./web/css/* ./web/js/*');
    exec('rm -rf web/js/translations/*');
    exec('php bin/console pim:install:assets --env=prod');
    exec('php bin/console assets:install --symlink web');
    exec('php bin/console oro:translation:dump');
    exec('yarn run webpack');

    return $this->render('PimcWhiteLabelBundle:Default:index.html.twig');
}

但这不起作用,可能是因为它以 www-data 用户身份执行脚本,我不知道。现在我正在尝试创建命令。有没有通过 symfony 做到这一点的好方法,如果有人知道,在 symfony 中这样做的最佳途径是什么。所以我创建了一个命令,我只需要指导如何处理这个:

protected function execute(InputInterface $input, OutputInterface $output)
{
    $argument = $input->getArgument('argument');

    if ($input->getOption('option')) {
        // my exec commands
    }

    $output->writeln('Command result.');
}

感谢您的所有帮助。

【问题讨论】:

  • 您说“这不起作用”,究竟是什么?你能提供任何错误信息吗?输出?
  • 感谢您的回复,我添加了一个答案,但是我不知道这是否是最好的方法,但它现在有效。

标签: php symfony akeneo


【解决方案1】:

我用 exec 命令解决了这个问题,由于某种原因它开始工作了 :)

protected function execute(InputInterface $input, OutputInterface $output)
{
    exec('rm -rf web/js/translations/*');
    exec('php bin/console pim:install:assets --env=prod');
    exec('php bin/console assets:install --symlink web');
    exec('php bin/console oro:translation:dump');
    exec('yarn run webpack');

    $output->writeln('Translations dumped successfully.');
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-02
  • 1970-01-01
  • 2013-08-06
  • 1970-01-01
相关资源
最近更新 更多