complete document service

This commit is contained in:
iIronside
2022-11-16 14:24:52 +03:00
parent 5c0badaf92
commit c52dd918db
20 changed files with 649 additions and 177 deletions

View File

@ -15,7 +15,6 @@ class m221108_125006_drop_unnecessary_tables_for_document extends Migration
$this->dropTable('accompanying_document');
$this->dropTable('document_field_value');
$this->dropTable('template_document_field');
$this->dropTable('document_field');
$this->dropTable('document');
$this->dropTable('template');
}
@ -48,13 +47,6 @@ class m221108_125006_drop_unnecessary_tables_for_document extends Migration
$this->addForeignKey('document_manager', 'document', 'manager_id', 'manager', 'id');
$this->createTable('{{%document_field}}', [
'id' => $this->primaryKey(),
'title' => $this->string(),
'field_template' => $this->string(),
]);
$this->createTable('{{%template_document_field}}', [
'id' => $this->primaryKey(),
'template_id' => $this->integer(11)->notNull(),

View File

@ -0,0 +1,71 @@
<?php
use common\models\DocumentField;
use yii\db\Migration;
/**
* Class m221115_094557_add_update_default_and_add_new_fields_in_document_field_table
*/
class m221115_094557_update_default_and_add_new_fields_in_document_field_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$documentFields = DocumentField::find()->all();
foreach ($documentFields as $documentField) {
$documentField->field_template = '${' . $documentField->field_template . '}';
$documentField->update();
}
Yii::$app->db->createCommand()->batchInsert('document_field', [ 'title', 'field_template'],
[
['№ договора', '${contract_number}'],
['Название', '${title}'],
['Компания', '${company}'],
['Представитель', '${manager}'],
['Компания контрагент', '${contractor_company}'],
['Представитель контрагента', '${contractor_manager}']
])->execute();
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
Yii::$app->db->createCommand()->delete('document_field',
[
'in', 'title', [
'№ договора',
'Название',
'Компания',
'Представитель',
'Компания контрагент',
'Представитель контрагента',
]
])->execute();
$documentFields = DocumentField::find()->all();
foreach ($documentFields as $documentField) {
$documentField->field_template = str_replace(['${', '}'], '', $documentField->field_template);
$documentField->update();
}
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m221115_094557_add_update_default_andaddnewfieldsin_document_field_table cannot be reverted.\n";
return false;
}
*/
}