CakePHP Migrations: The "template" option does not exist - php

I am getting following error when executing
bin/cake migrations create Initial
Error:
[InvalidArgumentException]
The "template" option does not exist.
Plugin is loaded and working.
// Edit: I am using CakePHP 3.0 RC1 fresh installation on a virtualbox with vagrant
Maybe this output helps:
Exception trace:
() at /var/www/projects/vendor/symfony/console/Symfony/Component/Console/Input/Input.php:180
Symfony\Component\Console\Input\Input->getOption() at /var/www/projects/vendor/robmorgan/phinx/src/Phinx/Console/Command/Create.php:130
Phinx\Console\Command\Create->execute() at /var/www/projects/vendor/cakephp/migrations/src/ConfigurationTrait.php:145
Migrations\Command\Create->execute() at /var/www/projects/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:253
Symfony\Component\Console\Command\Command->run() at /var/www/projects/vendor/symfony/console/Symfony/Component/Console/Application.php:874
Symfony\Component\Console\Application->doRunCommand() at /var/www/projects/vendor/symfony/console/Symfony/Component/Console/Application.php:195
Symfony\Component\Console\Application->doRun() at /var/www/projects/vendor/symfony/console/Symfony/Component/Console/Application.php:126
Symfony\Component\Console\Application->run() at /var/www/projects/vendor/cakephp/migrations/src/Shell/MigrationsShell.php:70
Migrations\Shell\MigrationsShell->main() at n/a:n/a
call_user_func_array() at /var/www/projects/vendor/cakephp/cakephp/src/Console/Shell.php:387
Cake\Console\Shell->runCommand() at /var/www/projects/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php:200
Cake\Console\ShellDispatcher->_dispatch() at /var/www/projects/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php:171
Cake\Console\ShellDispatcher->dispatch() at /var/www/projects/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php:122
Cake\Console\ShellDispatcher::run() at /var/www/projects/bin/cake.php:20
I hope you can help me.
Thx

I am afraid that this is a bug in cakephp/migrations
Look into:
/vendor/cakephp/migrations/src/Command/Create.php
configure() is not calling its parent so changes in underlying phinx library are not taken into account, namely addition of "template" option which is the problem in this case.
IMO configure() should call parent::configure() and leave calls of setName(), setDescription() etc. to phinx - there is an issue open here https://github.com/cakephp/migrations/issues/53

Related

php artisan migrate fails due to laravel command

I have a laravel command that contains a user entity. I wrote a migration to modify the user table. When running php artisan migrate, I get an error because the user entity does not match the database (because this migration will make those changes).
I suspect that this means that the migrate command's process includes setting up laravel commands. Is there a way I can run php artisan migrate and the laravel command code not run?
I'm running laravel 5.1 and php 7.1.
Edit:
I didn't post any code, because it's not even getting to the migration. Here is the error message (the command was php artisan migrate).
This may be helpful was well. This is in the laravel command class that is causing the error. I can comment it out and the migration runs fine. That would be annoying to do for production though.
$userRepo = $repositoryFactory->getRepository(User::class);
$this->defaultUser = $userRepo->find(3000);
I just thought I should also include part of the stack trace that is in the laravel log file for this error.
#0 /project-path/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(176): Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\DBAL\Driver\PDOException))
#1 /project-path/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(150): Doctrine\DBAL\DBALException::wrapException(Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Driver\PDOException), 'An exception oc...')
#2 /project-path/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(915): Doctrine\DBAL\DBALException::driverExceptionDuringQuery(Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Driver\PDOException), 'SELECT t0.user_...', Array)
#3 /project-path/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php(712): Doctrine\DBAL\Connection->executeQuery('SELECT t0.user_...', Array, Array)
#4 /project-path/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php(730): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->load(Array, NULL)
#5 /project-path/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(462): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadById(Array)
#6 /project-path/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php(154): Doctrine\ORM\EntityManager->find('...', Array, NULL, NULL)
#7 /project-path/Emailer.php(53): Doctrine\ORM\EntityRepository->find(3000)
#8 /project-path/QuoteStaleEmailer.php(25): Emailer->__construct(...)
#9 [internal function]: QuoteStaleEmailer->__construct(...)
#10 /project-path/vendor/laravel/framework/src/Illuminate/Container/Container.php(780): ReflectionClass->newInstanceArgs(Array)
#11 /project-path/vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('...', Array)
#12 /project-path/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('Servi...', Array)
According to Laravel 8 documentation , before renaming a column/table, ensure that you have installed the doctrine/dbal library via the Composer package manager.
Please run composer require doctrine/dbal to install
I came up with a decent work around. I don't know the correct terms to describe it, but looking at the stack trace, laravel sets up containers during a php artisan command. That includes containers for laravel command.
$this->defaultUser = $userRepo->find(3000) line was in the constructor, which meant it ran when the containers are setup. This causes an error because, the database for the user does not match the app setting for the user (because the migration hasn't run yet).
I moved the line to the getter function instead and set the default user there if it's empty, which isn't used when setting up the containers.
I tried installing laravel-websockets v2 and this error popped up when trying to migrate the tables. you need to install "doctrine/dbal" into your project and then run the migration
run composer require doctrine/dbal
run php artisan migrate

Aspect mock 'Go\ParserReflection\ReflectionFile' not found

I am trying to use aspect mock with codeception tests.
From their documentation it is not clear how to configure.
https://github.com/Codeception/AspectMock
Include AspectMock\Kernel into tests/_bootstrap.php.
I do not have such file. Should I create it? Where should I include it?
My directory structure of codeception is:
test/codeception/acceptance.
I have file SummaryCest.php in test/codeception/acceptance.
Since I do not have _bootstrap.php file, I decided to try in SummaryCest - before declaring a class:
include __DIR__.'/../../../vendor/autoload.php'; // composer autoload
$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
'debug' => true,
'includePaths' => [__DIR__.'/../../../'],
'excludePaths' => [__DIR__.'../../../vendor'],
'cacheDir' => '/tmp/datamanager',
]);
I do not know do I really need to exclude vendor directory, but I saw such suggestions. If that is mandatory, it should be written probably in readme which I did not see.
In includePaths there should be visible all my project files.
I have function in SummaryCest.php
public function correctSummaryCounts(AcceptanceTester $I)
{
\AspectMock\Test::double(SummaryController::class, ['get' => null]);
}
and when I run test
php codecept.phar run test/codeception/acceptance/SummaryCest.php
I get message
==== Redirecting to Composer-installed version in vendor/codeception ====
Codeception PHP Testing Framework v2.3.5
Powered by PHPUnit 6.2.4 by Sebastian Bergmann and contributors.
PHP Fatal error: Uncaught Error: Class 'Go\ParserReflection\ReflectionFile' not found in /var/www/warehouseDataManager/vendor/codeception/aspect-mock/src/AspectMock/Intercept/BeforeMockTransformer.php:16
Stack trace:
#0 /var/www/warehouseDataManager/vendor/goaop/framework/src/Instrument/Transformer/CachingTransformer.php(124): AspectMock\Intercept\BeforeMockTransformer->transform(Object(Go\Instrument\Transformer\StreamMetaData))
#1 /var/www/warehouseDataManager/vendor/goaop/framework/src/Instrument/Transformer/CachingTransformer.php(83): Go\Instrument\Transformer\CachingTransformer->processTransformers(Object(Go\Instrument\Transformer\StreamMetaData))
#2 /var/www/warehouseDataManager/vendor/goaop/framework/src/Instrument/ClassLoading/SourceTransformingLoader.php(134): Go\Instrument\Transformer\CachingTransformer->transform(Object(Go\Instrument\Transformer\StreamMetaData))
#3 /var/www/warehouseDataManager/vendor/goaop/framework/src/Instrument/ClassLoading/SourceTransformingLoader.php(101): Go\Instrument\ClassLoading\SourceTran in /var/www/warehouseDataManager/vendor/codeception/aspect-mock/src/AspectMock/Intercept/BeforeMockTransformer.php on line 16
Can you explain me how to configure this?
Also I saw in readme
$userModel = test::double('UserModel', ['tableName' => 'my_users']);
but test is not even found. So I tried to use \AspectMock\Test which is at least found.
Notice that the error is throw before even running my test function. When I tried running before class declaration
$kernel->init();
it already gives same error.
_bootstrap.php files are no longer created automatically by Codeception.
To enabled them you have to add
settings:
bootstrap: _bootstrap.php
to codeception.yml file
and manually create _bootstrap.php files in tests directory and in every suite.
http://codeception.com/docs/reference/Configuration
ReflectionFile issue looks like autoloading issue.

PHP artisan optimize returns error on bitBucket Pipeline

I'm trying to use bitBucket Pipeline with a Laravel. But everytime that run the pipeline return the follow error:
> post-install-cmd: Illuminate\Foundation\ComposerScripts::postInstall
> post-install-cmd: php artisan optimize --verbose
Generating optimized class loader
Compiling common classes
Script php artisan optimize --verbose handling the post-install-cmd event returned with an error
[RuntimeException]
Error Output:
Exception trace:
() at phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:196
Composer\EventDispatcher\EventDispatcher->doDispatch() at phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:94
Composer\EventDispatcher\EventDispatcher->dispatchScript() at phar:///usr/local/bin/composer/src/Composer/Installer.php:350
Composer\Installer->run() at phar:///usr/local/bin/composer/src/Composer/Command/InstallCommand.php:134
Composer\Command\InstallCommand->execute() at phar:///usr/local/bin/composer/vendor/symfony/console/Command/Command.php:256
Symfony\Component\Console\Command\Command->run() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:838
Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:189
Symfony\Component\Console\Application->doRun() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:167
Composer\Console\Application->doRun() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:120
Symfony\Component\Console\Application->run() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:98
Composer\Console\Application->run() at phar:///usr/local/bin/composer/bin/composer:43
require() at /usr/local/bin/composer:25
bitbucket-pipelines.yml:
# This is a sample build configuration for PHP.
# Check our guides at https://confluence.atlassian.com/x/VYk8Lw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: phpunit/phpunit:5.0.3
pipelines:
default:
- step:
script: # Modify the commands below to build your repository.
- composer install --verbose
The problem was solved, I needed to set some environments variable.
To be more specific, I use a collect errors' service called rollbar (really good by the way)
And in config/services.php it was setted like that:
'rollbar' => [
'access_token' => env('ROLLBAR_ACCESS_TOKEN'),
'level' => env('ROLLBAR_LEVEL', 'error'),
],
I just needed to set ROLLBAR_ACCESS_TOKEN variable in Settings/PIPELINES/Environment variables on BitBucket

Symfony is suddenly failing with "The service "session.storage.metadata_bag" has a dependency on a non-existent parameter"

I upgraded from Symfony 3.1.5 to 3.2.0 yesterday morning and everything was fine up until an hour or so ago.
Now Symfony throws the following exception upon any type of access, including console commands:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
The service "session.storage.metadata_bag" has a dependency on a
non-existent parameter "session.metadata.storage_key".
I have tried the following:
Backed out my most recent changes
Deleted var/cache/*
Here is the exception trace:
Exception trace:
() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:100
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->get() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php:56
Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag->get() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:217
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->resolveString() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:187
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->resolveValue() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:177
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->resolveValue() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php:39
Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass->process() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php:120
Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:565
Symfony\Component\DependencyInjection\ContainerBuilder->compile() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:484
Symfony\Component\HttpKernel\Kernel->initializeContainer() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:116
Symfony\Component\HttpKernel\Kernel->boot() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:68
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:122
Symfony\Component\Console\Application->run() at /Volumes/Data01/Projects/Beck/WWUI/site/bin/console:29
As you can see, it's part of Symfony, and not my code.
I am at a loss.
Has anybody else seen this?
Suggestions?
Edit 1:
Based on Dagon's suggestion that I check session.xml, and seeing that it appears correct, I decided to replace the
<argument>%session.metadata.storage_key%</argument>
tag with
<argument>_sf2_meta</argument>
in session.xml. This resulted in a new, similar error:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
The service
"64e3c91c625381e3c2c0184cf9ea0c6d5353986d77aa111949ca6fb8b17a8f07_2"
has a dependency on a non-existent parameter "validator.mapping.
cache.prefix".
This isn't really an answer per-se, but is is a fix.
I renamed vendor to vendor-HOLD and then ran composer install. Problem gone.
I did a diff on the old and new session.xml files and found that the definition of the parameter was different. The version causing the error contained:
<parameter string="session.metadata.storage_key">_sf2_meta</parameter>
The newly installed version contained:
<parameter key="session.metadata.storage_key">_sf2_meta</parameter>
instead. Obviously other files were incorrect, as well, based on the experimental edit I did to session.xml. No clue as to what happened, but it's nice that composer install fixed it. Oh, and yes, I deleted vendor-HOLD afterwards.

Trouble with ZFTool: Module (ZFTool) could not be initialized

ZFTool is the maintenance tool for Zend Framework applications. There are several ways to install it. I use it from a PHAR file.
$ mkdir -p /usr/lib/ZendFramework/zftool
$ cd /usr/lib/ZendFramework/zftool
$ wget http://packages.zendframework.com/zftool.phar
$ ln -s /usr/lib/ZendFramework/zftool/zftool.phar /usr/bin/zf
$ chmod 755 /usr/bin/zf
It works, when I execute the tool outside of a ZF application. But now I tried this whithin an application and get this error:
root#devvm:/usr/lib/ZendFramework/test# cd /path/to/application/ root#devvm:/path/to/application# zf PHP Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (ZFTool) could not be initialized.' in /path/to/application/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php:175 Stack trace:
#0 /path/to/application/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /path/to/application/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('ZFTool')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /path/to/application/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /path/to/application/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php( in /path/to/application/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php on line 175
Why does it happen? How to avoid this behavior?
It appears you need to install zftool into your project. user2900416 kind of hinted at this, but I think it is more correct to install zftool using composer like so for each project:
composer.phar require zendframework/zftool:dev-master
This solved it for me. It is discussed in an issue here: https://github.com/zendframework/ZFTool/issues/51
Check the case of the module.php file:
Make sure your **M**odule.php file is written with a capital M otherwise the file may not be found. This took me a day to bug test so I really hope I save someone the same trouble!
I got the same problem. This is what I did to fix it with 2 steps:
(1) Download ZFTool zipball as suggested by manual installation at http://framework.zend.com/manual/2.1/en/modules/zendtool.introduction.html.
(2) Unzip the zipball under your application's module/ directory with directory name as ZFTool/.
Then, the Module(ZFTool) has been installed in your application and can be initialized by either invoking
"zftool.phar create module ModuleName"
or
"zf.php create module ModuleName" where zf.php is in the zipball.
It looks REALLY stupid to copy the ZFTool module inside each application but I have spent days in trying to find a better one without any luck.n Hope someone can propose one.

Categories