How can I configure doctrine with migrations? - doctrine

I have this problem when I try to generate a migration from the terminal. How can I configure doctrine with migration?
https://i.ibb.co/HqWYBdT/imagen.png

'doctrine' => [
'migrations_configuration' => [
'orm_default' => [
'table_storage' => [
'table_name' => 'migrations',
'version_column_name' => 'version',
'version_column_length' => 1024,
'executed_at_column_name' => 'executedAt',
'execution_time_column_name' => 'executionTime',
],
'migrations_paths' => [
'Migrations' => 'data/Migrations',
], // an array of namespace => path
'migrations' => [], // an array of fully qualified migrations
'all_or_nothing' => false,
'check_database_platform' => true,
'organize_migrations' => 'none', // year or year_and_month
'custom_template' => null,
],
],
],

Related

how to upload spatie laravel stored backup to google drive?

i am trying to upload backup on google drive using laravel spatie package i followed these steps
https://gist.github.com/sergomet/f234cc7a8351352170eb547cccd65011
my backup is created successfully g-drive is integrated successfully but when perform action backup:run it gives this error mostly file not found and in the last it says
backup failed because: unlink C:\xampp\htdocs\newfolder\storage\app/backup-temp\temp\2020-11-07-20-06-19.zip) resource temporarily unavailable
and here is my config/backup.php
<?php
return [
'backup' => [
'name' => config('GOOGLE_DRIVE_FOLDER_ID' , 'laravel-backup'),
'source' => [
'files' => [
'include' => [
],
'exclude' => [
base_path('vendor'),
base_path('node_modules'),
],
'followLinks' => false,
],
'databases' => [
'mysql',
],
],
'database_dump_compressor' => null,
'destination' => [
'filename_prefix' => '',
'disks' => [
'local' , 'google'
],
],
'temporary_directory' => storage_path('app/backup-temp'),
],
'notifications' => [
'notifications' => [
\Spatie\Backup\Notifications\Notifications\BackupHasFailed::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\UnhealthyBackupWasFound::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\CleanupHasFailed::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\BackupWasSuccessful::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\HealthyBackupWasFound::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\CleanupWasSuccessful::class => ['mail'],
],
'notifiable' => \Spatie\Backup\Notifications\Notifiable::class,
'mail' => [
],
'slack' => [
'webhook_url' => '',
'channel' => null,
'username' => null,
'icon' => null,
],
],
'monitorBackups' => [
[
'name' => env('GOOGLE_DRIVE_FOLDER_ID' , 'laravel-backup'),
'disks' => ['local'],
'newestBackupsShouldNotBeOlderThanDays' => 1,
'storageUsedMayNotBeHigherThanMegabytes' => 5000,
],
],
'cleanup' => [
'strategy' => \Spatie\Backup\Tasks\Cleanup\Strategies\DefaultStrategy::class,
'defaultStrategy' => [
'keepAllBackupsForDays' => 7,
'keepDailyBackupsForDays' => 16,
'keepWeeklyBackupsForWeeks' => 8,
'keepMonthlyBackupsForMonths' => 4,
'keepYearlyBackupsForYears' => 2,
'deleteOldestBackupsWhenUsingMoreMegabytesThan' => 5000,
],
],
];
my .env
GOOGLE_DRIVE_CLIENT_ID=183462809528-gqhvm96rpsvhccp4lll55soms.apps.googleusercontent.com
GOOGLE_DRIVE_CLIENT_SECRET=T7OaNoN5t2GBHU4hvBVKX
GOOGLE_DRIVE_REFRESH_TOKEN="1//04Z70eIYBuRvgCgYIARAAGAQSNwF-L9Ir1riNcqKpwiOYeFdP6LlXhpcRgDPiMLbZvZS0UKQtDrEpqizRpLwah-Y2-WdmOs"
GOOGLE_DRIVE_FOLDER_ID=1245H1fYLxa8q0LJD1uTAe-chX8W44ALJ
To fix this error set the name to an empty string in the config/backup.php.
'name' => '',
In the following video link, the solution to this error is explained in detail:
https://www.youtube.com/watch?v=6kxXkrlRuJU
I am sure it will be helpful. Or you can also check out the article on -
How To Setup Laravel Backup On Google Drive?

Yii2: Remove controller from URL

I am using the advanced template.
I created all my actions on the SiteController, so all my urls are domain.com/site/something, and I need to remove the word "site" from the url so it will be domain.com/something.
I tried the following rules based on this question
'urlManager' => [
'class' => 'yii\web\UrlManager',
'showScriptName' => false,
'enablePrettyUrl' => true,
'rules' => array(
'/<action:\w+>/<id:\d+>' => 'site/<action>',
'/<action:\w+>' => 'site/<action>',
'/noticia/<slug>' => 'site/noticia',
),
],
also tried this based on this other question:
'urlManager' => [
'class' => 'yii\web\UrlManager',
'showScriptName' => false,
'enablePrettyUrl' => true,
'baseUrl' => 'http://localhost/websites/transcita/app/frontend/web',
'rules' => array(
[
'pattern' => '<action:\w+>',
'route' => 'site/<action>'
],
[
'pattern' => '<action:\w+>/<id:\d+>',
'route' => 'site/<action>'
],
'/noticia/<slug>' => 'site/noticia',
),
],
but neither is not working. I get a 404 when I type domain.com/something.
I also tried without the first / and it didn't work either.
Any thoughts?
Another way:
'rules' => [
'<alias:\w+>' => 'site/<alias>',
],
Try with:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
// ...
// last rule
'<action:(.*)>' => 'site/<action>',
],
],

Rewrite url in yii2

How can I rewrite urls in Yii2. I want to rewrite url
/post/index?id=1
to
/post/1-example
You need to add following rules code for urlManager in config/main.php(if advance template) or web.php.
[
'components' => [
'urlManager' => [
'showScriptName' => false,
'enablePrettyUrl' => true,
'enableStrictParsing' => false,
'rules' => [
'post/<id:\d+>-example' => 'post/index',
],
],
],
]
[
'components' => [
'urlManager' => [
'showScriptName' => false,
'enablePrettyUrl' => true,
'enableStrictParsing' => false,
'rules' => [
'post/<id:\d+>-<title:\w+>' => 'post/index',
],
],
],
]
You need to add below code to your backend/config/main.php under components section:
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',),
],
I'd posted just because ians should be generic for all entire project.

Yii2 Advanced app, different session for frontend and backend with subdomains

I have a problem with my Yii2 app.
I have a advanced-app with frontend and backend parts on different domains (subdomain). I use webvimark user management module, but I think the problem is not in it.
Frontend app -> domain.com
Backend app -> admin.domain.com
So I have problem with login in backend, it is not working.
I enter login and password, and after submit form I see login form again.
'user' => [
'identityClass' => 'webvimark\modules\UserManagement\models\User',
'enableAutoLogin' => true,
'identityCookie' => [
'name' => '_backendIdentity',
'domain' => 'admin.domain.com',
],
'class' => 'webvimark\modules\UserManagement\components\UserConfig',
],
and
'session' => [
'name' => 'BACKENDSESSID',
'cookieParams' => [
'domain' => 'admin.domain.com',
],
],
Any ideas?
Update #1: My config located: /backend/config/main.php
Update #2: There was a problem when transferring backend on a subdomain
Okey, there was a problem with the configuration of the module, as well as the wrong config in the frontend.
Backend:
'user' => [
'identityClass' => 'webvimark\modules\UserManagement\models\User',
'enableAutoLogin' => true,
'identityCookie' => [
'name' => '_backendIdentity',
'domain' => 'backend.test.dev',
],
'class' => 'webvimark\modules\UserManagement\components\UserConfig',
'on afterLogin' => function ($event) {
\webvimark\modules\UserManagement\models\UserVisitLog::newVisitor($event->identity->id);
},
],
'session' => [
'name' => 'BACKENDSESSID',
'cookieParams' => [
'domain' => 'backend.test.dev',
],
],
Frontend:
'user' => [
'identityClass' => 'webvimark\modules\UserManagement\models\User',
'enableAutoLogin' => true,
'identityCookie' => [
'name' => '_frontendIdentity',
'path' => '/',
],
'class' => 'webvimark\modules\UserManagement\components\UserConfig',
'on afterLogin' => function ($event) {
\webvimark\modules\UserManagement\models\UserVisitLog::newVisitor($event->identity->id);
}
],
'session' => [
'name' => 'FRONTENDSESSID',
'cookieParams' => [
'path' => '/',
],
],

How to always show single validation message in ZF2 validators?

I have the following input:
private function addBirthdayElement()
{
return $this->add(
array(
'type' => 'DateSelect',
'name' => 'x_bdate',
'options' => [
'label' => 'astropay_birthday',
'label_attributes' => array(
'class' => 'astropay-label'
),
'create_empty_option' => true,
'render_delimiters' => false,
],
'attributes' => array(
'required' => true,
'class' => 'astropay-input',
)
)
);
}
It has the following filter:
public function addBirthdayFilter()
{
$time = new \DateTime('now');
$eighteenYearAgo = $time->modify(sprintf('-%d year', self::EIGHTEEN_YEARS))->format('Y-m-d');
$this->add(
[
'name' => 'x_bdate',
'required' => true,
'validators' => [
[
'name' => 'Between',
'break_chain_on_failure' => true,
'options' => [
'min' => 1900,
'max' => $eighteenYearAgo,
'messages' => [
Between::NOT_BETWEEN => 'astropay_invalid_birth_date_18',
Between::NOT_BETWEEN_STRICT => 'astropay_invalid_birth_date_18',
]
]
],
[
'name' => 'Date',
'break_chain_on_failure' => true,
'options' => [
'messages' => [
Date::INVALID => 'astropay_invalid_birth_date',
Date::FALSEFORMAT => 'astropay_invalid_birth_date',
Date::INVALID_DATE => 'astropay_invalid_birth_date',
],
]
],
],
]
);
return $this;
}
However, putting an empty date, I get the error message defined for:
Date::INVALID_DATE
But it's not the overridden one. The break_chain_on_failure works for the two validators I have defined, but the default Zend message is always there. For example I get this as an error in my form:
The input does not appear to be a valid date
astropay_invalid_birth_date_18
How can I display only the overidden error messages and 1 at a time?
You can use a message key in your validator configuration instead of a messages array to always show a single message per validator.
For example, replace this:
'options' => [
'messages' => [
Date::INVALID => 'astropay_invalid_birth_date',
Date::FALSEFORMAT => 'astropay_invalid_birth_date',
Date::INVALID_DATE => 'astropay_invalid_birth_date',
],
]
with this one:
'options' => [
'message' => 'Invalid birth date given!',
]

Resources