OXID专业服务的控制台,用于OXID eShop


README

OXID PS Console是一个用于OXID eShop的Symfony控制台应用程序。它是社区和项目驱动的,读写访问类似于公共维基百科(如Wikipedia)。

以下命令可用

  • cache:clear - 清除OXID缓存
  • views:update - 重新生成数据库视图
  • module:activate - 在商店中激活模块
  • module:generate - 生成新的模块脚手架
  • module:fix - 根据元数据内容修复模块链
  • migration:generate - 生成新的迁移文件
  • migration:run - 运行迁移脚本

为了向后兼容,以下命令仍然可用(但已弃用

  • db:update - 更新数据库视图
  • g:migration - 生成新的迁移文件
  • g:module - 生成新的模块脚手架
  • list - (默认) 所有可用命令列表
  • migrate - 运行迁移脚本

获取哪个版本?

安装

使用Composer将控制台添加到您的项目中

composer require oxid-professional-services/oxid-console

入门

vendor/bin/oxid list

定义自己的命令

  • 类必须扩展 Symfony\Component\Console\Command\Command
  • 将以下内容添加到您的模块(composer包)的services.yaml json中
  services:
    oxid_community.moduleinternals.module.fix.command:
      class: OxidCommunity\ModuleInternals\Command\ModuleFixCommand
      tags:
      - { name: 'console.command' }

命令的模板

<?php

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;

/**
 * My own command
 *
 * Demo command for learning
 */
class MyOwnCommand extends Command
{

    /**
     * {@inheritdoc}
     */
    public function configure()
    {
        $this->setName('my:own');
        $this->setDescription('Demo command for learning');
        $this->addOption('demo', 'd', InputOption::VALUE_NONE, 'run demo');
    }

    /**
     * {@inheritdoc}
     */
    public function execute(InputInterface $input, OutputInterface $output)
    {
        if ($input->getOption('demo')) {
            $output->writeln('You typed in --demo or -d also');
        }

        $output->writeln('My demo command finished');
    }
}

有关更多示例,请参阅 https://symfony.ac.cn/doc/current/components/console.html

迁移

警告当前实现不会触发OXID核心迁移"oe-eshop-doctrine_migration"。

OXID控制台项目包括迁移处理。让我们通过运行vendor/bin/oxid migration:generate "add amount field to demo module"来生成示例迁移。

控制台应用程序生成了migration/20140312161434_addamountfieldtodemomodule.php文件及其内容。

<?php

class AddAmountFieldToDemoModuleMigration extends oxMigrationQuery
{

    /**
     * {@inheritdoc}
     */
    public function up()
    {
        // TODO: Implement up() method.
    }

    /**
     * {@inheritdoc}
     */
    public function down()
    {
        // TODO: Implement down() method.
    }
}

迁移处理器可以运行带有您提供的时间戳的迁移(如果没有提供时间戳,则假定时间戳为当前时间戳)。它内部保存了哪些迁移查询已执行,并知道哪些迁移查询向上或向下。

一旦生成了此文件,我们运行vendor/bin/oxid migration:run

Running migration scripts
[DEBUG] Migrating up 20140312161434 addamountfieldtodemomodulemigration
Migration finished successfully

现在让我们再次运行相同的命令

Running migration scripts
Migration finished successfully

注意:没有运行迁移脚本

好的,现在让我们使用vendor/bin/oxid migration:run 2013-01-01命令运行具有过去给定时间戳的迁移

Running migration scripts
[DEBUG] Migrating down 20140312161434 addamountfieldtodemomodulemigration
Migration finished successfully

它执行了我们的迁移查询向下,因为给定的时间戳我们不应该执行该迁移查询。

示例

以下是一个快速示例,说明迁移查询将列添加到oxuser表中

<?php
// FILE: 20140414085723_adddemoculumntooxuser.php

class AddDemoCulumnToOxUserMigration extends oxMigrationQuery
{

    /**
     * {@inheritdoc}
     */
    public function up()
    {
        if ($this->_columnExists('oxuser', 'OXDEMO')) {
            return;
        }

        $sSql = "ALTER TABLE  `oxuser`
                 ADD  `OXDEMO`
                    CHAR( 32 )
                    CHARACTER SET utf8
                    COLLATE utf8_general_ci
                    NULL
                    DEFAULT NULL
                    COMMENT  'Demo field for migration'";

        oxDb::getDb()->execute($sSql);
    }

    /**
     * {@inheritdoc}
     */
    public function down()
    {
        if (!$this->_columnExists('oxuser', 'OXDEMO')) {
            return;
        }

        oxDb::getDb()->execute('ALTER TABLE `oxuser` DROP `OXDEMO`');
    }
}

迁移查询法

  • 文件名必须遵循YYYYMMDDHHiiss_description.php格式
  • 必须扩展oxMigrationQuery抽象类
  • 类名必须与描述相同,并在名称末尾附加Migration单词

注意:最好使用生成器来创建迁移查询

相关项目