I have been using Doctrine and Migrations in my ZF2 project for a few weeks without issue. I have been executing migrations by specifying my own configuration file:
vendor/bin/doctrine-module migrations:diff --configuration=/path/to/migrations-config.xml
I recently brought in Codeception into my project via composer and when I recently went to execute a new migration (with the same above command), I received the following error:
[InvalidArgumentException]
Migrations directory data/DoctrineORMModule/Migrations does not exist
This is not the directory I have specified in my configuration file. At first I thought Doctrine Migrations was completely ignoring my --configuration argument. When I traced it through, I saw that Doctrine Migrations wasn't using my --configuration argument because it had already loaded a config file.
Would anyone know where this config file may be pulling in from? I can work around the issue for the time being by commenting out the conditional in AbstractCommand getMigrationConfiguration(), but long term I'd rather not have to rely on this. I'll also try and remove codeception and see if that has any impact. Any help is appreciated.
As it turns out, I was able to move Doctrine migrations configuration into my ZF2 module config. In my module.config.php, I have the following specified (Api is the module name):
'doctrine' => array(
'driver' => array(
'application_entities' => array(
'class' =>'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/Api/Entity')
),
'orm_default' => array(
'drivers' => array(
'Api\Entity' => 'application_entities'
)
)
),
'migrations_configuration' => array(
'orm_default' => array(
'directory' => 'data/migrations',
'namespace' => 'My\Namespace\Migrations',
'table' => 'migrations',
),
),
),
This allows me to run Doctrine migrations commands without having to specify a configuration file, for example:
vendor/bin/doctrine-module migrations:diff
I see an alternative in using a stand-alone doctrine-migration.phar command:
php doctrine-migrations.phar migrations:migrate --configuration=config.xml --db-configuration=db-config.xml
To make this work, you need to download doctrine-migrations.phar from here: https://github.com/doctrine/migrations
Related
I have a Centos7 VPS with AWS CLI installed on the /home directory. I've added my credentials into aws configure and it's generated the following files:
/home/.aws/credentials
/home/.aws/config
If I run the following code, it fails:
$client = new Aws\Lightsail\LightsailClient([
'region' => 'eu-west-2',
'version' => '2016-11-28'
]);
The error message is:
AccessDeniedException (client): User: arn:aws:sts::523423432423:assumed-role/AmazonLightsailInstanceRole/i-0eb5b2155b08e5185 is not authorized to perform
However if I add my credentials like so it works:
$credentials = new Aws\Credentials\Credentials('key', 'secret');
$client = new Aws\Lightsail\LightsailClient([
'region' => 'eu-west-2',
'version' => '2016-11-28',
'credentials' => $credentials
]);
Do I need to do something extra in order to get my script to read the /home/.aws/credentials file?
Do I need to do something extra in order to get my script to read the /home/.aws/credentials file?
Yes, you need to put the .aws/credentials directory in the home directory of the user running the command. This will be something like /home/username instead meaning that the full path to the credentials will be /home/username/.aws/credentials. It does not matter where you installed the aws command to.
Following code works well in PHP 5.6.
require_once '../aws/aws-autoloader.php';
$config = [
'region' => 'ap-south-1',
'version' => 'latest',
'credentials' => [
'key' => '...',
'secret' => '...'
]
];
$sdk = new Aws\Sdk($config);
$client = $sdk->createS3();
But on PHP 7, it through error:
Fatal error: Uncaught TypeError: Argument 1 passed to Aws\Common\Client\AbstractClient::__construct() must be an instance of Aws\Common\Credentials\CredentialsInterface, array given, called in /var/www/html/webservice/vendor/aws3/Aws/Sdk.php on line 316 and defined in /var/www/html/aws-sdk/vendor/aws/aws-sdk-php/src/Aws/Common/Client/AbstractClient.php:75 Stack trace: #0 /var/www/html/webservice/vendor/aws3/Aws/Sdk.php(316): Aws\Common\Client\AbstractClient->__construct(Array) #1 /var/www/html/webservice/vendor/aws3/Aws/Sdk.php(291): Aws\Sdk->createClient('S3', Array) #2 index.php(14): Aws\Sdk->__call('createS3', Array) thrown in /var/www/html/aws-sdk/vendor/aws/aws-sdk-php/src/Aws/Common/Client/AbstractClient.php on line 75
Please suggest me how can I make it work on PHP 7.
Thanks.
UPDATE: I have both AWS SDK version 2 & 3 in my project. this might be a issue of conflict. Then how to solve the conflict?
This problem doesn't have any issue with PHP 7.0.
It's the case of conflict SDK ver 2 & 3.
This two sdk can't be used together. so I had to upgrade to sdk 3.
Currently I have some locales subdirectories , which are correctly set in the configuration
config/application.rb
config.i18n.load_path += Dir["#{Rails.root.to_s}/config/locales/**/*.{rb,yml}"]
I have already 2 locales files , and I can get easily the translations :
config/locales/admin/dashboard.en.yml
en:
dashboard:
title: Dashboard
config/locales/admin/dashboard.fr.yml
fr:
dashboard:
title: Tableau de bord
irb(main):014:0> I18n.locale = :en
=> :en
irb(main):015:0> I18n.t("dashboard.title")
=> "Dashboard"
irb(main):016:0> I18n.locale = :fr
=> :fr
irb(main):017:0> I18n.t("dashboard.title")
=> "Tableau de bord"
Now I added 2 other locales files ( quite similar to previous ones...) into the SAME subdirectory 'locales/admin'
# =============
config/locales/admin/sheet.en.yml
en:
sheet:
title: Sheet
config/locales/admin/sheet.fr.yml
fr:
sheet:
title: Table
I RESTARTED the server ... and tried wo success to get the new added translations
irb(main):010:0> I18n.locale = :en
=> :en
irb(main):011:0> I18n.t("sheet.title")
=> "translation missing: en.sheet.title"
irb(main):012:0> I18n.locale = :fr
=> :fr
irb(main):013:0> I18n.t("sheet.title")
=> "translation missing: fr.sheet.title"
translations missing in BOTH languages? so I guess something is wrong in the subdirectories definition in the application.rb config file, as I checked the Rails.application.config.i18n.load_path ,a dn the newly added files ARE NOT in the path ..
"..../config/locales/admin/dashboard.en.yml",
"..../config/locales/admin/dashboard.fr.yml",
but not
"..../config/locales/admin/sheet.en.yml",
"..../config/locales/admin/sheet.fr.yml",
thanks for suggestions
It seems this issue has been already detected and it's related to the 'spring' process..
# https://github.com/rails/spring/issues/408
# rafaelfranca May 28
I think you got this error because you added the locale file after you
started the spring process for your environment, so when you add the
file it is not loaded inside the spring process. When you change the
application.rb the spring process is reloaded and your locale is now
working.
I changed one line ( added one blank line ...) in the application.rb than I restarted the server , and the new translations are found
rafael stated the rails console should restart the spring
Any rails command starts springs. rails console, rails generate,
rails server. You can stop the spring process with spring stop.
so, after ADDING a new locale file, better stopping spring before restarting the server
spring stop
rails server ( or rails console )
Change application.rb => Restart the Rails server
I would like to add that any time you make any change to application.rb you must restart the server for the change to take effect, not just the i18n component.
I am working through deploying a Zf2 app with Doctrine on Aws Beanstalk. Composer is running and setting up everything and afterwards I run a symfony console command to generate the databases and schemas using the parameters specified in my config. I followed the examples out of here to get the rds params for the configuration.
http://www.michaelgallego.fr/blog/2013/05/24/how-to-deploy-safe-zf-2-applications-on-amazon-elastic-beanstalk/
All this works up to accessing the website. At which point it gives me a Pdo error accessing the database.
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002]
No such file or directory' in
/var/app/current/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43 Stack
trace: #0
/var/app/current/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php(43):
PDO->__construct('mysql:host=loca...', 'username', 'password', Array) #
/var/app/current/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php(45):
Doctrine\DBAL\Driver\PDOConnection->__construct('mysql:host=loca...', 'username',
'password', Array) #2
/var/app/current/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(360):
Doctrine\DBAL\Driver\PDOMySql\Driver->connect(Array, 'username', 'password', Array) #3
/var/app/current/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429):
Doctrine\DBAL\Connection->connect() #4
/var/app/current/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389):
Doctrine\DBAL\Connection->getDatabasePlatformVersion() #5
/var/app/current/vendor/doctrine/dbal/lib/Doctrine/DBAL/C in
The zf2 app is apigility. After deployment if I log into the server and run the php command
php public/index.php development enable
It will produce the same error as the frontend website.
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002]
No such file or directory' in
/var/app/current/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
I am setting up the database schemas through console commands that are in the aws config. This does setup the correct database and runs the schema and data import.
.ebextensions/composer.config
container_commands:
01installDev:
command: "/usr/bin/composer.phar install --dev"
02makeDatabase:
command: "/usr/bin/php /var/app/ondeck/cwg.php database:create"
03createDatabase:
command: "/usr/bin/php /var/app/ondeck/cwg.php database:fresh"
config/autoload/database.global.php
return array(
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' => 'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver',
'params' => array(
'host' => $_SERVER['RDS_HOSTNAME'],
'port' => $_SERVER['RDS_PORT'],
'user' => $_SERVER['RDS_USERNAME'],
'password' => $_SERVER['RDS_PASSWORD'],
'dbname' => 'api_default',
),
),
),
),
);
When I run the console commands I am just creating a doctrine instance with the parameters in these files, that is the only difference from the zf2 app, but I do get the correct params.
Trying to debug this I dumped the $options and $pdo variables inside a doctrine orm module factory.
vendor/doctrine/doctrine-orm-module/src/DoctrineORMModule/Service/DBALConnectionFactory.php
var_dump($options);die();
object(DoctrineORMModule\Options\DBALConnection)#369 (8) { ["configuration":protected]=>
string(11) "orm_default" ["eventmanager":protected]=> string(11) "orm_default
["pdo":protected]=> NULL ["driverClass":protected]=> string(36)
"Doctrine\DBAL\Driver\PDOMySql\Driver" ["wrapperClass":protected]=> NULL
["params":protected]=> array(5) {
["host"]=> string(9) "localhost"
["port"]=> string(4) "3306"
["user"]=> string(8) "username"
["password"]=> string(8) "password"
["dbname"]=>string(8) "database"
} ["doctrineTypeMappings":protected]=> array(0) {
["__strictMode__":protected]=> bool(true) }
var_dump($pdo);die();
NULL
The parameters that are being used are the default doctrine parameters. I dont know if this is to early in the process if zf2 hasn't loaded the config files but I haven't found any other places related to the connection that will var_dump before the error. What am I doing wrong either in my aws configuration setup, or firewall rules between the rds servers and the api (which I assumed beanstalk configured for you since it set everything up), or not doing my zf2 configuration correctly? Any help is appreciated.
edit
I moved the var_dump further down to line 60
var_dump($connection->getParams());die();
array(8) { ["driverClass"]=> string(36) "Doctrine\DBAL\Driver\PDOMySql\Driver
["wrapperClass"]=> NULL ["pdo"]=> NULL ["host"]=> string(9) "localhost" ["port"]=>
string(4) "3306" ["user"]=> string(8) "username" ["password"]=> string(8) "password
["dbname"]=> string(8) "database" }
I think this pretty well shows that Doctrine does not see my configuration at all and somehow I am doing something or not doing something.
Somehow inside the application.config.php file a static location was set for configuration.
'config_glob_paths' => array(
'/home/myhome/api/config/autoload/{,*.}{global,local}.php'
),
Once I changed that to
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php'
),
Doctrine started getting the correct params.
I've just started with Zend framework 2, with Doctrine. I want to set up unit testing for my Album module.
When I run c:\wamp\www\zf2-tutorial\module\Album\test > phpunit from command prompt,
I get following error:
PHPUnit 3.7.10 by Sebastian Bergmann.
Configuration read from C:\wamp\www\zf2-tutorial\module\Album\test\phpunit.xml.d
ist
.FFE
Time: 2 seconds, Memory: 8.25Mb
There was 1 error:
1) AlbumTest\Controller\AlbumControllerTest::testIndexActionCanBeAccessed
Zend\ServiceManager\Exception\ServiceNotFoundException: Zend\ServiceManager\Serv
iceManager::get was unable to fetch or create an instance for doctrine.entityman
ager.orm_default
C:\wamp\www\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Service
Manager\ServiceManager.php:452
C:\wamp\www\zf2-tutorial\module\Album\src\Album\Controller\AlbumController.php:2
5
C:\wamp\www\zf2-tutorial\module\Album\src\Album\Controller\AlbumController.php:3
3
C:\wamp\www\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Mvc\Con
troller\AbstractActionController.php:88
C:\wamp\www\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\EventMa
nager\EventManager.php:464
C:\wamp\www\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\EventMa
nager\EventManager.php:208
C:\wamp\www\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Mvc\Con
troller\AbstractController.php:107
C:\wamp\www\zf2-tutorial\module\Album\test\AlbumTest\Controller\AlbumControllerT
est.php:71
--
There were 2 failures:
1) AlbumTest\Controller\AlbumControllerTest::testDeleteActionCanBeAccessed
Failed asserting that 302 matches expected 200.
C:\wamp\www\zf2-tutorial\module\Album\test\AlbumTest\Controller\AlbumControllerT
est.php:54
2) AlbumTest\Controller\AlbumControllerTest::testEditActionCanBeAccessed
Failed asserting that 302 matches expected 200.
C:\wamp\www\zf2-tutorial\module\Album\test\AlbumTest\Controller\AlbumControllerT
est.php:64
FAILURES!
Tests: 4, Assertions: 3, Failures: 2, Errors: 1.
The root of the issue seems to be:
Zend\ServiceManager\Exception\ServiceNotFoundException: Zend\ServiceManager\Serv
iceManager::get was unable to fetch or create an instance for doctrine.entityman
ager.orm_default from test..
I don't understand this, please help!
Okay finally got it!!
I changed my TestConfig.php.dist inside module/Album/test to
<?php
return array(
'modules' => array(
'DoctrineModule',
'DoctrineORMModule',
'Album',
),
'module_listener_options' => array(
'config_glob_paths' => array(
'../../../config/autoload/{,*.}{global,local}.php',
),
'module_paths' => array(
'module',
'vendor',
),
),
);
so basically just added two missing modules, DoctrineModule and DoctrineORMModule, and the phpunit command showed no errors!
Hope it helps others.