【发布时间】:2016-07-21 12:23:37
【问题描述】:
所以,我有一个这样调用的脚本:
./cli_dispatch.phpsh varnish_instance_update update 123.4.5.6,45.29.102.3
基本上,它会获取应在数据库中更新的 IP 列表。
<?php
namespace Bene\VarnishInstanceUpdate\Cli;
if (!defined('TYPO3_cliMode')) {
die('You cannot run this script directly!');
}
class Updater {
/**
* console arguments
*
* @var array
*/
protected $args;
/**
* @var \Mittwald\Varnishcache\Domain\Repository\ServerRepository
* @inject
*/
protected $serverRepository;
function __construct() {
$this->args = $_SERVER['argv'];
$this->clearServers();
}
function clearServers() {
$this->serverRepository->removeAll();
}
}
$instance = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('\\Bene\\VarnishInstanceUpdate\\Cli\\Updater');
不幸的是,这将以错误“致命错误:在 null 上调用成员函数 removeAll()”结束。 findAll()、count()、add()等都是一样的。
如何访问 extbase 方法?我错过了什么?
编辑:(某种)解决方案
多亏了 Jost,我让它工作了,有点。
<?php
namespace Bene\VarnishInstanceUpdate\Command;
use \TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
if (!defined('TYPO3_cliMode')) {
die('You cannot run this script directly!');
}
class UpdateCommandController extends CommandController {
/**
* @var \Mittwald\Varnishcache\Domain\Repository\ServerRepository
* @inject
*/
protected $serverRepository;
/**
* Clears the server table
*/
function clearServersCommand() {
$this->serverRepository->removeAll();
}
}
在 ext_localconf.php 中
if (TYPO3_MODE === 'BE') {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][$_EXTKEY] =
\Bene\VarnishInstanceUpdate\Command\UpdateCommandController::class;
}
你这样称呼它:
./cli_dispatch.phpsh extbase update:clearservers
但是:removeAll() 使用 findAll(),它需要一个 storagePid,它需要 TypoScript 配置才能工作。我想这是一个后续问题。
【问题讨论】:
-
只是作为一个提示:获取配置管理器的实例并使用它的 API 来获取您需要的 ts。
标签: typo3 extbase typo3-6.2.x