The Symfone "doctrine:fixtures:load" command missing - php

I have Symfony 3.1 project with Doctrine and
doctrine/doctrine-fixtures-bundle and
doctrine/data-fixtures installed.
However, when i run a console command
php bin/console doctrine:fixtures:load
i get a message saying that there are no commands defined in the doctrine:fixtures namespace.
The class Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand exists.
Please suggest how to fix that.

Run first php bin/console and see if the command appear in the list.
If it doesn't, then you have to load the bundle in the AppKernel.php
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();

php bin/console default environment is PROD
and fixtures proper installation is require-dev
so proper function call is:
php bin/console --env=dev doctrine:fixtures:load

Also rm -rf var/cache worked for me (after the bundle registration)

Data Fixtures Mechanism requires a special bundle. It is not included in Sf by default.
Check: http://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html
and install it.
Bundle called DoctrineFixturesBundle. You can also find there many useful information how to use fixtures.
So that why you've got message "Command is not defined".

Related

Symfony - can't run created console command

I've created a file called GenerateRandomUserCommand.php inside vendor/symfony/console/Command. Its namespace is set to: Symfony\Component\Console\Command it extends Command aswell. Clean composer and Symfony installation. The problem is, I can't make command working. I write: php bin/console mycommand (it is set of course in class) and I have a message: Command "mycommand" is not defined.
What's the problem? I did nothing in kernel or config, everything is default.
It's need to see that not working command file. But I can suggest to you use symfony maker bundle.
First, require bundle for dev env: composer require maker --dev
Then simply type in console bin/console make:command. After typing name it was generate command skeleton with some simple example. And I beleive that's all you need =)
The problem was, I must register command. Despite of autoregistering provided by Symfony...

Symfony there are no commands defined in the "make" namespace

Following the documentation found here I enter php bin/console make:entity Product in Terminal and get the following error:
[Symfony\Component\Console\Exception\CommandNotFoundException]
There are no commands defined in the "make" namespace.
Maybe you were using the prod environment?
The website-skeleton puts the Maker Bundle in the require-dev section of your composer.json by default:
"require-dev": {
...
"symfony/maker-bundle": "^1.0",
...
}
If you've set APP_ENV=prod in your .env file and ran bin/console it would ignore all dev requirements and thus wouldn't enable the Maker Bundle.
Simply enabling the dev environment again (APP_ENV=dev) would do the trick then.
make is a command of doctrine component. Just add doctrine maker.
composer require doctrine maker
https://symfony.com/doc/current/doctrine.html#installing-doctrine
You need Symfony 3.4 or higher. For Symfony 3.4 you will need to add it to the registerBundles function in config/AppKernerl():
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
// [...]
$bundles[] = new \Symfony\Bundle\MakerBundle\MakerBundle();
}
Bear in mind that the environment where it is installed is 'dev'.
try
composer remove maker
composer require maker --dev
and then
php bin/console make:entity Product
https://symfony.com/doc/current/bundles/SymfonyMakerBundle/index.html
You must define the "dev" env in the command line :
php bin/console --env dev
php bin/console make:entity Product --env dev
The problem just happend to me.
I was in test environment.
You have to be in dev environment.
Check APP_ENV value in .env file. It must be the following :
APP_ENV=dev
I think you are in prod environment. Check if your the value of APP_ENV inside .env file is not equals to prod.
In case you generate a .env.local file, you have to delete it in your dev environment.
You can use composer for installer maker bundle, you have install a light version of symfony.
composer require symfony/maker-bundle
but if you have this problem surely need composer doctrine and security
composer require doctrine/orm
with
require doctrine/doctrine-bundle
And
composer require symfony/security-bundle
composer require doctrine/doctrine-migrations-bundle
Now you have this with php bin/console !
make make:auth Creates a Guard authenticator of
different flavors
make:command Creates a new console command class
make:controller Creates a new controller class
make:crud Creates CRUD for Doctrine entity class
make:docker:database Adds a database container to your
docker-compose.yaml file
make:entity Creates or updates a Doctrine entity
class, and optionally an API Platform resource
make:fixtures Creates a new class to load Doctrine
fixtures
make:form Creates a new form class
make:message Creates a new message and handler
make:messenger-middleware Creates a new messenger middleware
make:migration Creates a new migration based on
database changes
make:registration-form Creates a new registration form system
make:reset-password Create controller, entity, and
repositories for use with symfonycasts/reset-password-bundle
make:serializer:encoder Creates a new serializer encoder class
make:serializer:normalizer Creates a new serializer normalizer
class
make:stimulus-controller Creates a new Stimulus controller
make:subscriber Creates a new event subscriber class
make:test [make:unit-test|make:functional-test]
Creates a new test class
make:twig-extension Creates a new Twig extension class
make:user Creates a new security user class
make:validator Creates a new validator and constraint
class
make:voter Creates a new security voter class
If you have installed symfony / maker-bundle for the dev mode you will only be able to use it for this mode. If you are in
prod mode then go to dev mode and try again
Try composer require symfony/maker-bundle --dev it work for me.
composer require symfony/maker-bundle --dev
To fix the problem you just create new project with (full properties), here is command for create a project:
symfony new --full project-name
after you create project like the command above, you now can able to use (make).

server:run Exception There are no commands defined in the "server" namespace

When I run the server using php bin/console server:run I get the following error.
There are no commands defined in the "server" namespace.
When I run php bin/console command I egt the following output. Which does't show any server: commands.
Symfony 3.3.0-DEV (kernel: app, env: dev, debug: true)
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-e, --env=ENV The environment name [default: "dev"]
--no-debug Switches off debug mode
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
about Displays information about the current project
help Displays help for a command
list Lists commands
app
app:download-beameemail download beame emails.
app:download-businessunits download businessunits.
app:download-drivers download drivers.
app:download-fleets download fleets.
app:download-fmpositions download fm_positions.
app:download-fmtrips download fm_trips.
app:download-fmunits download fm_units.
app:download-skypositions download skytrack_positions.
app:download-skyunits download skytrack_units.
app:download-vehicles download vehicles.
assets
assets:install Installs bundles web assets under a public web directory
cache
cache:clear Clears the cache
cache:pool:clear Clears cache pools
cache:warmup Warms up an empty cache
config
config:dump-reference Dumps the default configuration for an extension
debug
debug:config Dumps the current configuration for an extension
debug:container Displays current services for an application
debug:event-dispatcher Displays configured listeners for an application
debug:router Displays current routes for an application
debug:swiftmailer [swiftmailer:debug] Displays current mailers for an application
debug:translation Displays translation messages information
debug:twig Shows a list of twig functions, filters, globals and tests
doctrine
doctrine:cache:clear-collection-region Clear a second-level cache collection region.
doctrine:cache:clear-entity-region Clear a second-level cache entity region.
doctrine:cache:clear-metadata Clears all metadata cache for an entity manager
doctrine:cache:clear-query Clears all query cache for an entity manager
doctrine:cache:clear-query-region Clear a second-level cache query region.
doctrine:cache:clear-result Clears result cache for an entity manager
doctrine:database:create Creates the configured database
doctrine:database:drop Drops the configured database
doctrine:database:import Import SQL file(s) directly to Database.
doctrine:ensure-production-settings Verify that Doctrine is properly configured for a production environment.
doctrine:generate:crud [generate:doctrine:crud] Generates a CRUD based on a Doctrine entity
doctrine:generate:entities [generate:doctrine:entities] Generates entity classes and method stubs from your mapping information
doctrine:generate:entity [generate:doctrine:entity] Generates a new Doctrine entity inside a bundle
doctrine:generate:form [generate:doctrine:form] Generates a form type class based on a Doctrine entity
doctrine:mapping:convert [orm:convert:mapping] Convert mapping information between supported formats.
doctrine:mapping:import Imports mapping information from an existing database
doctrine:mapping:info
doctrine:query:dql Executes arbitrary DQL directly from the command line.
doctrine:query:sql Executes arbitrary SQL directly from the command line.
doctrine:schema:create Executes (or dumps) the SQL needed to generate the database schema
doctrine:schema:drop Executes (or dumps) the SQL needed to drop the current database schema
doctrine:schema:update Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata.
doctrine:schema:validate Validate the mapping files.
fos
fos:js-routing:debug Displays currently exposed routes for an application
fos:js-routing:dump Dumps exposed routes to the filesystem
generate
generate:bundle Generates a bundle
generate:command Generates a console command
generate:controller Generates a controller
lint
lint:twig Lints a template and outputs encountered errors
lint:xliff Lints a XLIFF file and outputs encountered errors
lint:yaml Lints a file and outputs encountered errors
router
router:match Helps debug routes by simulating a path info match
security
security:check Checks security issues in your project dependencies
security:encode-password Encodes a password.
swiftmailer
swiftmailer:email:send Send simple email message
swiftmailer:spool:send Sends emails from the spool
translation
translation:update Updates the translation file
I've tried to fix it by running composer require symfony/symfony and composer update but it still doesn't show.
Is there anything else that I can try?
Edit below is my php info from php -version
PHP 7.0.15-0ubuntu0.16.04.4 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.15-0ubuntu0.16.04.4, Copyright (c) 1999-2017, by Zend Technologies
with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
EDIT 2
the directory vendor\symfon\symfony\src\Symfony\Bundle\FrameworkBundle\Command exists and contains the following files
AboutCommand.php
AbstractConfigCommand.php
AssetsInstallCommand.php
CacheClearCommand.php
CachePoolClearCommand.php
CacheWarmupCommand.php
ConfigDebugCommand.php
ConfigDumpReferenceCommand.php
ContainerAwareCommand.php
ContainerDebugCommand.php
EventDispatcherDebugCommand.php
RouterDebugCommand.php
RouterMatchCommand.php
TranslationDebugCommand.php
TranslationUpdateCommand.php
WorkflowDumpCommand.php
XliffLintCommand.php
YamlLintCommand.php
As I mentioned in my comment, in S3.3 the server commands have been moved to their own WebServerBundle. Some editing of AppKernel.php is required to activate the bundle. I suspect that many other developers might run into this once 3.3 is actually released and people try upgrading.
I make no promises but try updating AppKernel.php with:
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
if ('dev' === $this->getEnvironment()) {
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
}
}
I don't have a good test project to try it on but at least the commands should show up.
And in case anyone is wondering, all I did was to install a fresh development project and poked around a bit.
composer create-project symfony/framework-standard-edition s33 "3.3.*" --stability=dev
I also found this but it does not mention the need to update AppKernel.php
http://symfony.com/blog/new-in-symfony-3-3-webserverbundle
From the upgrade guide: https://github.com/symfony/symfony/blob/3.4/UPGRADE-3.3.md
The server:run, server:start, server:stop and server:status console commands have been moved to a dedicated bundle. Require symfony/web-server-bundle in your composer.json and register Symfony\Bundle\WebServerBundle\WebServerBundle in your AppKernel to use them.
As long as your composer.json has symfony/symfony in it then there is no need to add the web server bundle to it. Just need to adjust the AppKernel file.
run this command before starting the server.
composer require symfony/web-server-bundle --dev
you must execute this command:
composer req webserver
Type:
php bin/console
You'll see all the commands allowed.
If you want to use the server commands you should install it typing on your project:
composer require server --dev
run again
php bin/console
and you should be able to see it and use it.
As #Barh says, you must have APP_ENV=dev in your .env file.
Otherwise Symfony 4 will not be runnable in dev mode.
Verify that the correct APP_ENV is set in the environment.
In my case, it was critical.
you can put this:
php -S localhost: 8000 -t public
or if you are working on symfony 4.x try this command line in your browser:
symfony server: start
don't forget to install symfony CLI before this start from this:
https://symfony.com/download
Since symfony 4.2 and newer, theres is some changes so, to works you have to do this :
1: composer require symfony/web-server-bundle --dev
2: php bin\console --env=dev server:run
upgrading from symfony <3.3 to symfony >3.3 will cause this problem because the web server was extracted out to a separate bundle.
so you'll need to require this bundle:
composer require symfony/web-server-bundle --dev
and in your AppKernel
if ('dev' === $this->getEnvironment()) {
$bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
}
for more info: check here
I had same issue on Symfony 4 after switching in .env to prod. Some commands are not visible on prod.
You either need to swap to dev or:
bin/console --env=dev
And so to start server:
bin/console --env=dev server:run 0.0.0.0:8005
For symfony 4 and more you should type php -S 127.0.0.1:8000 -t public to start the server
Disabling firewall help
running......composer clear cache helped in allowing permission
running......composer req webserver helped clear my commands defined in the "server" namespace
Remove env.local file if you've it.
Reson:
Because server:run is not executing on production environment

Could not open file app/console Symfony 2.8

I am using Symfony 2.8 using Symfony 3 directory structure. After recent composer install it is complaining that
An error occurred when executing the "'cache:clear --no-warmup'" command: Could not open input file: app/console
I looked at the change log and could not find anything regarding this change is there anyway to fix this issue.
Do you have a console folder inside the app one ?
btw try to do php bin/console cache:clear --no-warmup
bin/console is the new directory in Symfony 3. It's maybe the same issue.
Create var directory.
Explanation:
vendor/sensio/distribution-bundle/Composer/ScriptHandler.php:462
protected static function useNewDirectoryStructure(array $options)
{
return isset($options['symfony-var-dir']) && is_dir($options['symfony-var-dir']);
}
So you need both to have symfony-var-dir in composer.json's extra and have this directory existing.

symfony2 tutorial - generate bundle

I am new to symfony2 but not to symfony. I am currently doing the symblog tutorial. Its going ok so far however I have come a little stuck on the generate bundle?
The tutorial says to run the following command
php app/console generate:bundle --namespace=Blogger/BlogBundle --format=yml
After completing that it should add reference/generate code to the bundle in the
app/AppKernel.php
app/config/routing.yml
However it has not added anything?... I'm a bit confused? The console outputs the following but the code references to the bundle have not been generated in the files
Welcome to the Symfony2 bundle generator
Your application code must be written in bundles. This command helps
you generate them easily.
Each bundle is hosted under a namespace (like Acme/Bundle/BlogBundle).
The namespace should begin with a "vendor" name like your company name, your
project name, or your client name, followed by one or more optional category
sub-namespaces, and it should end with the bundle name itself
(which must have Bundle as a suffix).
See http://symfony.com/doc/current/cookbook/bundles/best_practices.html#index-1 for more
details on bundle naming conventions.
Use / instead of \ for the namespace delimiter to avoid any problem.
Bundle namespace [Blogger/BlogBundle]:
You can use this without interaction . then it won't ask you anything
php app/console generate:bundle --namespace=Blogger/BlogBundle --format=yml --no-interaction
From generate:bundle --help
If you want to disable any user interaction, use --no-interaction but don't forget to pass all needed options:
php app/console generate:bundle --namespace=Acme/BlogBundle --dir=src [--bundle-name=...] --no-interaction
I have bash functions for these long commands.
genbundle () {
php app/console generate:bundle --namespace=$1/$2Bundle --bundle-name=$2Bundle --dir=src/ --format=yml
}
You can use it like this: "genbundle Acme Blog", It'll create a BlogBundle in the Acme app.
If I understood what's going on correctly, you have to go on the process. It's step-by-step where you answer the questions. Keep answering everything asked, and then the console will tell when it created the bundle.
Note: the value in [...] are the default value if you just press enter when the console asks you something.
Old Command:
php app/console generate:bundle --namespace=Blogger/BlogBundle --format=yml --no-interaction
In new symfony version 3.1.4, "app/console" is no more working.
Instead add "bin/console" in above command
So the New command will be
php bin/console generate:bundle --namespace=Blogger/BlogBundle --format=yml --no-interaction

Categories