Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions console/controllers/FillTableAController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?

namespace console\controllers;

use yii;
use yii\console\Controller;
use yii\helpers\Console;
use yii\base\Security;

class FillTableAController extends Controller
{
//Records count to generate
private $records_count = 1000;

/**
* Run command: yii fill-table-a
* @return int
* @throws yii\base\Exception
* @throws yii\db\Exception
*/
public function actionIndex()
{
$security = new Security();

Console::startProgress(0,$this->records_count);
Copy link
Copy Markdown

@primemix primemix May 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Console::startProgress(0, $this->records_count);
и ноль (цифры) желательно константой писать

for( $i=0;$i<$this->records_count;$i++ ) {
Copy link
Copy Markdown

@primemix primemix May 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for ($i = 0; $i <= $this->records_count; $i++)

Yii::$app->db->createCommand()->insert('table_a',['value'=>$security->generateRandomString(8)])->execute();
Copy link
Copy Markdown

@primemix primemix May 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yii::$app->db->createCommand()
->insert('table_a',['value'=>$security->generateRandomString(8)])
->execute();

и восемь константой, если не ясно почему могу объяснить

Console::updateProgress($i,$this->records_count);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Console::updateProgress($i, $this->records_count);

}
Console::endProgress('done'.PHP_EOL);

return 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут return 0; - не нужно.

}
}
24 changes: 24 additions & 0 deletions console/controllers/MoveDataController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace console\controllers;

use yii;
use yii\console\Controller;
use yii\helpers\Console;

class MoveDataController extends Controller
{
/**
* Run command: yii move-data
* @return int
* @throws yii\db\Exception
*/
public function actionIndex()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public function actionIndex(): void

{
$data_a = Yii::$app->db->createCommand('SELECT * FROM table_a')->queryAll();

Yii::$app->db->createCommand()->batchInsert('table_b',['id','value'],$data_a)->execute();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yii::$app->db->createCommand()
->batchInsert('table_b', ['id','value'], $data_a)
->execute();


return 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return 0; - не нужен

}
}
25 changes: 25 additions & 0 deletions console/migrations/m190516_082608_create_table_a.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use yii\db\Migration;

/**
* Class m190516_082608_create_table_a
*/
class m190516_082608_create_table_a extends Migration
{
public function safeUp()
{
$this->createTable(
'table_a',
[
'id' => $this->primaryKey(),
'value' => $this->string(),
]
);
}

public function safeDown()
{
$this->dropTable('table_a');
}
}
25 changes: 25 additions & 0 deletions console/migrations/m190516_090632_create_table_b.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use yii\db\Migration;

/**
* Class m190516_090632_create_table_b
*/
class m190516_090632_create_table_b extends Migration
{
public function safeUp()
{
$this->createTable(
'table_b',
[
'id' => $this->primaryKey(),
'value' => $this->string(),
]
);
}

public function safeDown()
{
$this->dropTable('table_b');
}
}