本文整理汇总了PHP中Drupal\Console\Style\DrupalStyle::success方法的典型用法代码示例。如果您正苦于以下问题:PHP DrupalStyle::success方法的具体用法?PHP DrupalStyle::success怎么用?PHP DrupalStyle::success使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Console\Style\DrupalStyle
的用法示例。
在下文中一共展示了DrupalStyle::success方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$siteName = $input->getArgument('name');
$directory = $input->getArgument('directory');
$fileSystem = $this->get('filesystem');
if (!$fileSystem->exists($directory)) {
$io->error(sprintf($this->trans('commands.site.import.local.messages.error-missing'), $directory));
return 1;
}
$drupal = $this->get('site');
if (!$drupal->isValidRoot($directory)) {
$io->error(sprintf($this->trans('commands.site.import.local.messages.error-not-drupal'), $directory));
return 1;
}
$environment = $input->getOption('environment') ?: 'local';
$siteConfig = [$environment => ['root' => $drupal->getRoot(), 'host' => 'local']];
$yaml = $this->get('yaml');
$dump = $yaml::dump($siteConfig);
$config = $this->getApplication()->getConfig();
$userPath = sprintf('%s/.console/sites', $config->getUserHomeDir());
$configFile = sprintf('%s/%s.yml', $userPath, $siteName);
try {
$fileSystem->dumpFile($configFile, $dump);
} catch (\Exception $e) {
$io->error(sprintf($this->trans('commands.site.import.local.messages.error-writing'), $e->getMessage()));
return 1;
}
$io->success(sprintf($this->trans('commands.site.import.local.messages.imported')));
}
示例2: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$configName = $input->getArgument('name');
$fileName = $input->getArgument('file');
$config = $this->getDrupalService('config.factory')->getEditable($configName);
$ymlFile = new Parser();
if (!empty($fileName) && file_exists($fileName)) {
$value = $ymlFile->parse(file_get_contents($fileName));
} else {
$value = $ymlFile->parse(stream_get_contents(fopen("php://stdin", "r")));
}
if (empty($value)) {
$io->error($this->trans('commands.config.import.single.messages.empty-value'));
return;
}
$config->setData($value);
try {
$config->save();
} catch (\Exception $e) {
$io->error($e->getMessage());
return 1;
}
$io->success(sprintf($this->trans('commands.config.import.single.messages.success'), $configName));
}
示例3: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$vocabularies = $this->getDrupalApi()->getVocabularies();
// Validate provided vocabularies
$vids = $input->getArgument('vocabularies');
$invalidVids = array_filter(array_map(function ($vid) use($vocabularies) {
if (!isset($vocabularies[$vid])) {
return $vid;
} else {
return null;
}
}, $vids));
if (!empty($invalidVids)) {
$io->error(sprintf($this->trans('commands.create.terms.messages.invalid-vocabularies'), implode(',', $invalidVids)));
return;
}
$limit = $input->getOption('limit') ?: 10;
$nameWords = $input->getOption('name-words') ?: 5;
$createTerms = $this->getDrupalApi()->getCreateTerms();
$terms = $createTerms->createTerm($vids, $limit, $nameWords);
$tableHeader = [$this->trans('commands.create.terms.messages.term-id'), $this->trans('commands.create.terms.messages.vocabulary'), $this->trans('commands.create.terms.messages.name')];
$io->table($tableHeader, $terms['success']);
$io->success(sprintf($this->trans('commands.create.terms.messages.created-terms'), $limit));
return;
}
示例4: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$uid = $input->getArgument('user');
$user = User::load($uid);
if (!$user) {
$io->error(sprintf($this->trans('commands.user.password.reset.errors.invalid-user'), $uid));
return;
}
$password = $input->getArgument('password');
if (!$password) {
$io->error(sprintf($this->trans('commands.user.password.reset.errors.empty-password'), $uid));
return;
}
try {
$user->setPassword($password);
$user->save();
// Clear all failed login attempts after setup new password to user account.
$this->getChain()->addCommand('user:login:clear:attempts', ['uid' => $uid]);
} catch (\Exception $e) {
$io->error($e->getMessage());
return;
}
$io->success(sprintf($this->trans('commands.user.password.reset.messages.reset-successful'), $uid));
}
示例5: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$modules = $input->getArgument('module');
$module_handler = $this->getDrupalService('module_handler');
$lock = $this->getDrupalService('lock');
// Try to acquire cron lock.
if (!$lock->acquire('cron', 900.0)) {
$io->warning($this->trans('commands.cron.execute.messages.lock'));
return;
}
if (in_array('all', $modules)) {
$modules = $module_handler->getImplementations('cron');
}
foreach ($modules as $module) {
if ($module_handler->implementsHook($module, 'cron')) {
$io->info(sprintf($this->trans('commands.cron.execute.messages.executing-cron'), $module));
try {
$module_handler->invoke($module, 'cron');
} catch (\Exception $e) {
watchdog_exception('cron', $e);
$io->error($e->getMessage());
}
} else {
$io->warning(sprintf($this->trans('commands.cron.execute.messages.module-invalid'), $module));
}
}
// Set last time cron was executed
\Drupal::state()->set('system.cron_last', REQUEST_TIME);
// Release cron lock.
$lock->release('cron');
$this->get('chain_queue')->addCommand('cache:rebuild', ['cache' => 'all']);
$io->success($this->trans('commands.cron.execute.messages.success'));
}
示例6: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$modules = $input->getArgument('module');
$composer = $input->getOption('composer');
$simulate = $input->getOption('simulate');
if (!$composer) {
$io->error($this->trans('commands.module.update.messages.only-composer'));
return 1;
}
if (!$modules) {
$io->error($this->trans('commands.module.update.messages.missing-module'));
return 1;
}
if (count($modules) > 1) {
$modules = " drupal/" . implode(" drupal/", $modules);
} else {
$modules = " drupal/" . current($modules);
}
if ($composer) {
$this->setComposerRepositories("default");
$command = 'composer update ' . $modules . ' --optimize-autoloader --prefer-dist --no-dev --root-reqs ';
if ($simulate) {
$command .= " --dry-run";
}
$shellProcess = $this->get('shell_process');
if ($shellProcess->exec($command)) {
$io->success(sprintf($this->trans('commands.module.update.messages.composer'), trim($modules)));
}
}
return 0;
}
示例7: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$application = $this->getApplication();
$manifest = $input->getOption('manifest') ?: 'http://drupalconsole.com/manifest.json';
$currentVersion = $input->getOption('current-version') ?: $application->getVersion();
$major = $input->getOption('major');
if (!extension_loaded('Phar') || !\Phar::running(false)) {
$io->error($this->trans('commands.self-update.messages.not-phar'));
$io->block($this->trans('commands.self-update.messages.instructions'));
return 1;
}
$io->info(sprintf($this->trans('commands.self-update.messages.check'), $currentVersion));
$updater = new Updater(null, false);
$strategy = new ManifestStrategy($currentVersion, $major, $manifest);
$updater->setStrategyObject($strategy);
if (!$updater->hasUpdate()) {
$io->info(sprintf($this->trans('commands.self-update.messages.current-version'), $currentVersion));
return 0;
}
$oldVersion = $updater->getOldVersion();
$newVersion = $updater->getNewVersion();
if (!$io->confirm(sprintf($this->trans('commands.self-update.questions.update'), $oldVersion, $newVersion), true)) {
return 1;
}
$io->comment(sprintf($this->trans('commands.self-update.messages.update'), $newVersion));
$updater->update();
$io->success(sprintf($this->trans('commands.self-update.messages.success'), $oldVersion, $newVersion));
// Errors appear if new classes are instantiated after this stage
// (namely, Symfony's ConsoleTerminateEvent). This suggests PHP
// can't read files properly from the overwritten Phar, or perhaps it's
// because the autoloader's name has changed. We avoid the problem by
// terminating now.
exit;
}
示例8: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$uid = $input->getArgument('user');
$user = User::load($uid);
if (!$user) {
$io->error(sprintf($this->trans('commands.user.password.reset.errors.invalid-user'), $uid));
return 1;
}
$password = $input->getArgument('password');
if (!$password) {
$io->error(sprintf($this->trans('commands.user.password.reset.errors.empty-password'), $uid));
return 1;
}
try {
$user->setPassword($password);
$user->save();
$schema = $this->database->schema();
$flood = $schema->findTables('flood');
if ($flood) {
$this - $this->chainQueue->addCommand('user:login:clear:attempts', ['uid' => $uid]);
}
} catch (\Exception $e) {
$io->error($e->getMessage());
return 1;
}
$io->success(sprintf($this->trans('commands.user.password.reset.messages.reset-successful'), $uid));
}
示例9: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$learning = $input->hasOption('learning') ? $input->getOption('learning') : false;
$address = $input->getArgument('address');
if (false === strpos($address, ':')) {
$address = sprintf('%s:8088', $address);
}
$finder = new PhpExecutableFinder();
if (false === ($binary = $finder->find())) {
$io->error($this->trans('commands.server.errors.binary'));
return;
}
$router = $this->getRouterPath();
$cli = sprintf('%s %s %s %s', $binary, '-S', $address, $router);
if ($learning) {
$io->commentBlock($cli);
}
$io->success(sprintf($this->trans('commands.server.messages.executing'), $binary));
$processBuilder = new ProcessBuilder(explode(' ', $cli));
$process = $processBuilder->getProcess();
$process->setWorkingDirectory($this->get('site')->getRoot());
$process->setTty('true');
$process->run();
if (!$process->isSuccessful()) {
$io->error($process->getErrorOutput());
}
}
示例10: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$styles = $input->getArgument('styles');
$result = 0;
$imageStyle = $this->entityTypeManager->getStorage('image_style');
$stylesNames = [];
if (in_array('all', $styles)) {
$styles = $imageStyle->loadMultiple();
foreach ($styles as $style) {
$stylesNames[] = $style->get('name');
}
$styles = $stylesNames;
}
foreach ($styles as $style) {
try {
$io->info(sprintf($this->trans('commands.image.styles.flush.messages.executing-flush'), $style));
$imageStyle->load($style)->flush();
} catch (\Exception $e) {
watchdog_exception('image', $e);
$io->error($e->getMessage());
$result = 1;
}
}
$io->success($this->trans('commands.image.styles.flush.messages.success'));
return $result;
}
示例11: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$output = new DrupalStyle($input, $output);
$this->getDrupalHelper()->loadLegacyFile('/core/includes/utility.inc');
$validators = $this->getValidator();
// Get the --cache option and make validation
$cache = $input->getArgument('cache');
$validated_cache = $validators->validateCache($cache);
if (!$validated_cache) {
$output->error(sprintf($this->trans('commands.cache.rebuild.messages.invalid_cache'), $cache));
return;
}
// Start rebuilding cache
$output->newLine();
$output->writeln(sprintf('<comment>%s</comment>', $this->trans('commands.cache.rebuild.messages.rebuild')));
// Get data needed to rebuild cache
$kernelHelper = $this->getKernelHelper();
$classLoader = $kernelHelper->getClassLoader();
$request = $kernelHelper->getRequest();
// Check cache to rebuild
if ($cache === 'all') {
// If cache is all, then clear all caches
drupal_rebuild($classLoader, $request);
} else {
// Else, clear the selected cache
$caches = $validators->getCaches();
$caches[$cache]->deleteAll();
}
$output->success($this->trans('commands.cache.rebuild.messages.completed'));
}
示例12: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$learning = $input->hasOption('learning') ? $input->getOption('learning') : false;
$address = $this->validatePort($input->getArgument('address'));
$finder = new PhpExecutableFinder();
if (false === ($binary = $finder->find())) {
$io->error($this->trans('commands.server.errors.binary'));
return;
}
$router = $this->getRouterPath();
$cli = sprintf('%s %s %s %s', $binary, '-S', $address, $router);
if ($learning) {
$io->commentBlock($cli);
}
$io->success(sprintf($this->trans('commands.server.messages.executing'), $binary));
$processBuilder = new ProcessBuilder(explode(' ', $cli));
$process = $processBuilder->getProcess();
$process->setWorkingDirectory($this->appRoot);
if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
$process->setTty('true');
} else {
$process->setTimeout(null);
}
$process->run();
if (!$process->isSuccessful()) {
$io->error($process->getErrorOutput());
}
}
示例13: downloadProject
/**
* @param \Drupal\Console\Style\DrupalStyle $io
* @param $project
* @param $version
* @param $type
* @return string
*/
public function downloadProject(DrupalStyle $io, $project, $version, $type)
{
$commandKey = str_replace(':', '.', $this->getName());
$io->comment(sprintf($this->trans('commands.' . $commandKey . '.messages.downloading'), $project, $version));
try {
$destination = $this->getDrupalApi()->downloadProjectRelease($project, $version);
$drupal = $this->getDrupalHelper();
$projectPath = sprintf('%s/%s', $drupal->isValidInstance() ? $drupal->getRoot() : getcwd(), $this->getExtractPath($type));
if (!file_exists($projectPath)) {
if (!mkdir($projectPath, 0777, true)) {
$io->error($this->trans('commands.' . $commandKey . '.messages.error-creating-folder') . ': ' . $projectPath);
return null;
}
}
$zippy = Zippy::load();
$archive = $zippy->open($destination);
$archive->extract($projectPath);
unlink($destination);
if ($type != 'core') {
$io->success(sprintf($this->trans('commands.' . $commandKey . '.messages.downloaded'), $project, $version, sprintf('%s/%s', $projectPath, $project)));
}
} catch (\Exception $e) {
$io->error($e->getMessage());
return null;
}
return $projectPath;
}
示例14: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$io->newLine();
$io->comment($this->trans('commands.router.rebuild.messages.rebuilding'));
$this->routerBuilder->rebuild();
$io->success($this->trans('commands.router.rebuild.messages.completed'));
}
示例15: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$httpClient = $this->getHttpClientHelper();
$siteName = $input->getArgument('site-name');
$version = $input->getArgument('version');
if ($version) {
$releaseSelected = $version;
} else {
// Getting Module page header and parse to get module Node
$io->info(sprintf($this->trans('commands.site.new.messages.getting-releases')));
// Page for Drupal releases filter by Drupal 8
$projectReleaseSelected = 'https://www.drupal.org/node/3060/release?api_version%5B%5D=7234';
// Parse release module page to get Drupal 8 releases
try {
$html = $httpClient->getHtml($projectReleaseSelected);
} catch (\Exception $e) {
$io->error($e->getMessage());
return;
}
$crawler = new Crawler($html);
$releases = [];
foreach ($crawler->filter('span.file a') as $element) {
if (strpos($element->nodeValue, ".tar.gz") > 0) {
$releaseName = str_replace('.tar.gz', '', str_replace('drupal-', '', $element->nodeValue));
$releases[$releaseName] = $element->nodeValue;
}
}
if (empty($releases)) {
$io->error($this->trans('commands.site.new.messages.no-releases'));
return;
}
$releaseSelected = $io->choice($this->trans('commands.site.new.messages.release'), array_keys($releases));
}
$releaseFilePath = 'http://ftp.drupal.org/files/projects/drupal-' . $releaseSelected . '.tar.gz';
// Destination file to download the release
$destination = tempnam(sys_get_temp_dir(), 'drupal.') . "tar.gz";
try {
// Start the process to download the zip file of release and copy in contrib folter
$io->info(sprintf($this->trans('commands.site.new.messages.downloading'), $releaseSelected));
$httpClient->downloadFile($releaseFilePath, $destination);
$io->info(sprintf($this->trans('commands.site.new.messages.extracting'), $releaseSelected));
$zippy = Zippy::load();
$archive = $zippy->open($destination);
$archive->extract('./');
try {
$filesyStem = new Filesystem();
$filesyStem->rename('./drupal-' . $releaseSelected, './' . $siteName);
} catch (IOExceptionInterface $e) {
$io->error(sprintf($this->trans('commands.site.new.messages.error-copying'), $e->getPath()));
}
$io->success(sprintf($this->trans('commands.site.new.messages.downloaded'), $releaseSelected, $siteName));
} catch (\Exception $e) {
$io->error($e->getMessage());
return false;
}
return true;
}