reports fix
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
namespace console\controllers;
|
||||
|
||||
|
||||
use common\models\Reports;
|
||||
use common\models\UserCard;
|
||||
use Yii;
|
||||
use yii\console\Controller;
|
||||
@ -21,11 +22,10 @@ class SqlController extends Controller
|
||||
{
|
||||
$model = UserCard::find()->all();
|
||||
foreach ($model as $item) {
|
||||
if(!$item->photo){
|
||||
if($item->gender === 1){
|
||||
if (!$item->photo) {
|
||||
if ($item->gender === 1) {
|
||||
$item->photo = '/profileava/f' . random_int(1, 6) . '.png';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$item->photo = '/profileava/m' . random_int(1, 10) . '.png';
|
||||
}
|
||||
$item->save();
|
||||
@ -38,4 +38,16 @@ class SqlController extends Controller
|
||||
{
|
||||
echo UserCard::generateUserForUserCard() . "\n";
|
||||
}
|
||||
|
||||
public function actionAddUserIdToReports()
|
||||
{
|
||||
$reports = Reports::find()->all();
|
||||
foreach ($reports as $report) {
|
||||
$report->user_id = $report->userCard->id_user;
|
||||
$report->save();
|
||||
echo "user $report->user_id changed\n";
|
||||
}
|
||||
|
||||
echo "script completed successfully\n";
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Class m240131_080048_add_user_id_column_at_reports_table
|
||||
*/
|
||||
class m240131_080048_add_user_id_column_at_reports_table extends Migration
|
||||
{
|
||||
private const TABLE_NAME = "reports";
|
||||
|
||||
private const COLUMN_NAME = "user_id";
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$this->addColumn(self::TABLE_NAME, self::COLUMN_NAME, $this->integer(11)->after("status"));
|
||||
$this->addForeignKey('fk_reports_user', self::TABLE_NAME, self::COLUMN_NAME, 'user', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
$this->dropForeignKey('fk_reports_user', self::TABLE_NAME);
|
||||
$this->dropColumn(self::TABLE_NAME, self::COLUMN_NAME);
|
||||
}
|
||||
|
||||
/*
|
||||
// Use up()/down() to run migration code without a transaction.
|
||||
public function up()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m240131_080048_add_user_id_column_at_reports_table cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Handles the dropping of table `{{%fk_reports_user_card_id_at_reports}}`.
|
||||
*/
|
||||
class m240131_132201_drop_fk_reports_user_card_id_at_reports_table extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$this->dropForeignKey("fk-reports-user_card_id", "reports");
|
||||
$this->dropIndex("idx-reports-user_card_id", "reports");
|
||||
$this->alterColumn("reports", "user_card_id", $this->integer(11));
|
||||
$this->alterColumn("reports", "status", $this->integer(1)->defaultValue(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user