symfony: getting error /usr/local/bin/: Permission denied in assetic:dump - symfony

My assetic configuration is:
assetic:
debug: '%kernel.debug%'
use_controller: false
filters:
less:
node: /usr/local/bin/
node_paths: [/usr/local/lib/node_modules]
apply_to: '\.less$'
when I run command bin/console assetic:dump then I am getting below error:
[Assetic\Exception\FilterException]
An error occurred while running:
'/usr/local/bin/' '/tmp/assetic_lessgyMQtZ'
Error Output:
sh: 1: /usr/local/bin/: Permission denied

Related

Got warning: 'WARNING [cache] Failed to save key' after update doctrine configuration

I got a warning: 'WARNING [cache] Failed to save key', after trying to update the doctrine configuration. this error appears when i run bin/console.
I tried updating the doctrine configuration to get rid of the deprecation warning I got.
Previously my doctrine configuration was like this:
orm:
entity_managers:
default:
metadata_cache_driver: apcu
with this configuration there are no errors or warnings that I get. there is only a deprecation notice.
then I try to update the configuration to be like this:
orm:
entity_managers:
default:
metadata_cache_driver:
type: pool
pool: doctrine.apcu_cache_pool
framework:
cache:
pools:
doctrine.apcu_cache_pool:
adapter: cache.adapter.apcu
and i got 'WARNING [cache] Failed to save key' when try run bin/console.
I know the problem is because I haven't enabled apc.enabled_cli in my php.ini.
but what I'm asking is why in my initial configuration the warning didn't appear even though apc.enabled_cli = 0
Thank you !

Symfony5 workflow with githubaction issue on database and migrations

Currently, I'm trying to set up a workflow with GitHub action.
I took example from https://github.com/shivammathur/setup-php/blob/master/examples/symfony-mysql.yml
My ci.yml is:
name: phpunit
on: [push]
jobs:
tests :
name: Running functional and unit test
runs-on: ubuntu-20.04
services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: false
MYSQL_ROOT_PASSWORD: symfony
MYSQL_DATABASE: symfony
ports:
- 3306/tcp
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: true
matrix:
php-versions: ['7.4-apache']
steps:
# —— Setup Github actions 🐙 —————————————————————————————————————————————
# https://github.com/actions/checkout (official)
- name: Checkout
uses: actions/checkout#v2
# https://github.com/shivammathur/setup-php (community)
- name: Setup PHP, extensions and composer with shivammathur/setup-php
uses: shivammathur/setup-php#v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml, ctype, iconv, intl, pdo, pdo_mysql, dom, filter, gd, iconv, json, mbstring, mysqli
env:
update: true
- name: Check PHP Version
run: php -v
# —— Composer 🧙‍️ —————————————————————————————————————————————————————————
- name: Validate composer.json and composer.lock
run: composer validate
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache#v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader
- run: composer require symfony/runtime
- name: Run Migration && Load Fixtures
run: |
composer require --dev symfony/orm-pack
php bin/console doctrine:database:drop --if-exists --force --env=test
php bin/console doctrine:database:create --if-not-exists --env=test
php bin/console doctrine:schema:update --env=test --force || echo "No migrations found or schema update failed"
php bin/console doctrine:migrations:migrate --env=test || echo "No migrations found or migration failed"
php bin/console doctrine:fixtures:load --no-interaction
env:
DATABASE_URL: mysql://root:symfony#127.0.0.1:${{ job.services.mysql.ports['3306'] }}/symfony
## —— NPM 🐱 ————————————————————————————————————————————————————————————
- name: npm install
uses: actions/setup-node#v2
with:
node-version: '14'
#registry-url: npm.fontawesome.com
- run: npm install
#env:
#NODE_AUTH_TOKEN: ${{ secrets.FONTAWESOME_NPM_AUTH_TOKEN }}
- run: npm run build
- run: php bin/phpunit
I'm getting issue in the step of Run migrations & load Fixtures':
ci error:
Ci error:
Error: Migration DoctrineMigrations\Version20220222101244 failed during Execution. Error: "An exception occurred while executing a query: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'user' already exists"
In ExceptionConverter.php line 47:
An exception occurred while executing a query: SQLSTATE[42S01]: Base table
or view already exists: 1050 Table 'user' already exists
I tried to remove schema update, this also lead into another error.
I also removed dropping database, then another error.
You create your schema twice:
First you do a doctrine:schema:update, that creates all tables like it is defined in your mapping.
Then you want to do the doctrine:migrations:migrate. I assume, that you have the CREATE TABLE definitions there, too. Thats why it complains.
If you remove this following line
php bin/console doctrine:schema:update --env=test --force || echo "No migrations found or schema update failed"
and have all setup in your migrations, it should work.

Unrecognized option "driver" under "sylius_money"

I have installed SyliusCartBundle following the docs and when I run "php app/console doctrine:schema:update --force" I get the following error:
[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
Unrecognized option "driver" under "sylius_money"
My config.yml looks like in here http://sylius.readthedocs.org/en/latest/bundles/SyliusCartBundle/installation.html
#\app\config\config.yml
sylius_cart:
resolver: app.cart_item_resolver # The id of our newly created service.
classes: ~ # This key can be empty but it must be present in the configuration.
sylius_order:
driver: doctrine/orm
sylius_money:
driver: doctrine/orm
I've submitted a PR to update the docs for the Sylius CartBundle.
The configuration should be at its most simplistic:
sylius_money: ~
This equates to the default options, which are:
sylius_money:
currency: EUR
locale: en
However in Symfony, I'd recommend this setting:
sylius_money:
locale: %locale%
Where %locale% is the value taking from app/config/parameters.yml.

Symfony2 doctrine:schema:update with multiple Entity Managers

I have two database connections in config.yml and two entity managers. Each are tied to a bundle.
The issue that I'm having is running unit tests, which start by creating a blank db and loading in data. It's creating both databases but i'm getting both sets of tables in each database, instead of one set of entities in one db and one in the other. Since two db connections isn't incredibly common, I'm having trouble finding some help on this.
doctrine:
dbal:
default_connection: default
...
connections:
default:
(conectioninfo)
seconddb:
(connectioninfo)
orm:
default_entity_manager: default
auto_generate_proxy_classes: "%kernel.debug%"
entity_managers:
default:
connection: default
mappings:
MycompanyCoreBundle: ~
seconddb:
connection: seconddb
mappings:
MycomanySecondBundle: ~
When running unit tests, the lines I have are:
php app/console doctrine:database:drop --force --env=test --connection=default
php app/console doctrine:database:create --env=test --connection=default
php app/console doctrine:schema:drop --force --no-interaction --env=test --em=default
php app/console doctrine:schema:update --force --no-interaction --env=test --em=default
php app/console doctrine:database:drop --force --env=test --connection=seconddb
php app/console doctrine:database:create --env=test --connection=seconddb
php app/console doctrine:schema:drop --force --no-interaction --env=test --em=seconddb
php app/console doctrine:schema:update --force --no-interaction --env=test --em=seconddb
When running all this, the output is
Successfully deleted cache entries.
Dropping database schema...
Database schema dropped successfully!
Updating database schema...
Database schema updated successfully! "91" queries were executed
The problem is that those 91 queries are a combination of both Entity folders in the two bundles. I'm missing somewhere to point them separately so they go into their respective databases.
I found the answer to this eventually. There isn't a way to specify a database for a Migration, so you basically have to run Migration twice on EM and then test for the db connection.
Within each migration file, you put in a line to ignore it if it's not the correct one. Thus, some files have
$this->skipIf( $this->connection->getDatabase() != 'dbone', 'Skipping database.' );
and others have
$this->skipIf( $this->connection->getDatabase() != 'dbtwo', 'Skipping database.' );
Then when you run these commands:
doctrine:migrations:migrate --em="default"
doctrine:migrations:migrate --em="orm"
Both will cycle through all your migration files but the ones that don't apply to that situation will be ignored.

Cannot find node_module less in dev environnement

In a symfony2 project, I use assetic with less filter.
Everything is ok in prod environnement, the command assetic:dump generates corrects css files.
But when I render the page in dev envrionnement, my css files tell me that the less module could not be find.
It looks like that:
[exception] 500 | Internal Server Error | Assetic\Exception\FilterException
[message] An error occurred while running:
"/usr/bin/node" "/tmp/assetic_lessb45F2E"
Error Output:
module.js:340
throw err;
^
Error: Cannot find module "less"
My config.yml seems to be good
assetic:
debug: %kernel.debug%
use_controller: false
filters:
cssrewrite: ~
less:
node: /usr/bin/node
node_paths: /usr/local/lib/node_modules
apply_to: "\.less$"
My project is served by Apache runned by www-data user.
I tried to chmod 777 my node_modules folder just in case.
Your config does not respect the right hierarchy, and no need to specify .less extension, ir-s default config for less filter :
assetic:
debug: %kernel.debug%
use_controller: false
node: /usr/bin/node
node_paths: /usr/lib/node_modules
filters:
cssrewrite: ~
less: ~
Check /usr/bin path if node binary is in there (or linked), but maybe you should define this binary (looks like you locally installed node) :
node: /usr/local/bin/node
node_paths: /usr/LOCAL/lib/node_modules

Resources