Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Apr 7, 2020
1 parent ec3f71b commit b45be50
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
43 changes: 43 additions & 0 deletions src/migrations/m200406_110601__alter_table__cms_search_phrase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* @author Semenov Alexander <[email protected]>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 28.08.2015
*/

use yii\db\Migration;

class m200406_110601__alter_table__cms_search_phrase extends Migration
{
public function safeUp()
{
$tableName = "cms_search_phrase";

$this->addColumn($tableName, "cms_site_id", $this->integer());

$result = \Yii::$app->db->createCommand(<<<SQL
UPDATE
`cms_search_phrase` as spts
LEFT JOIN cms_site site on site.code = spts.site_code
SET
spts.`cms_site_id` = site.id
SQL
)->execute();

$this->dropForeignKey("cms_search_phrase_site_code_fk", $tableName);
$this->dropColumn($tableName, "site_code");


$this->addForeignKey(
"{$tableName}__cms_site_id", $tableName,
'cms_site_id', '{{%cms_site}}', 'id', 'CASCADE', 'CASCADE'
);
}

public function safeDown()
{
echo "m200406_080601__alter_table__shop_order cannot be reverted.\n";
return false;
}
}
12 changes: 6 additions & 6 deletions src/models/CmsSearchPhrase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
* @property integer $result_count
* @property integer $pages
* @property string $ip
* @property string $site_code
* @property string $data_server
* @property string $data_session
* @property string $data_cookie
* @property string $data_request
* @property string $session_id
* @property integer|null $cms_site_id
*
* @property CmsSite $site
*/
Expand Down Expand Up @@ -71,7 +71,7 @@ public function rules()
[['data_server', 'data_session', 'data_cookie', 'data_request'], 'string'],
[['phrase'], 'string', 'max' => 255],
[['ip'], 'string', 'max' => 32],
[['site_code'], 'string', 'max' => 15],
[['cms_site_id'], 'integer'],

['data_request', 'default', 'value' => $_REQUEST],
['data_server', 'default', 'value' => $_SERVER],
Expand All @@ -94,11 +94,11 @@ public function rules()
],

[
['site_code'],
['cms_site_id'],
'default',
'value' => function (self $model, $attribute) {
if (\Yii::$app->cms->site) {
return \Yii::$app->cms->site->code;
return \Yii::$app->cms->site->id;
}

return null;
Expand All @@ -125,7 +125,7 @@ public function attributeLabels()
'result_count' => Yii::t('skeeks/search', 'Documents Found'),
'pages' => Yii::t('skeeks/search', 'Pages Count'),
'ip' => Yii::t('skeeks/search', 'Ip'),
'site_code' => Yii::t('skeeks/search', 'Site'),
'cms_site_id' => Yii::t('skeeks/search', 'Site'),
'data_server' => Yii::t('skeeks/search', 'Data Server'),
'data_session' => Yii::t('skeeks/search', 'Data Session'),
'data_cookie' => Yii::t('skeeks/search', 'Data Cookie'),
Expand All @@ -138,6 +138,6 @@ public function attributeLabels()
*/
public function getSite()
{
return $this->hasOne(CmsSite::className(), ['code' => 'site_code']);
return $this->hasOne(CmsSite::className(), ['id' => 'cms_site_id']);
}
}

0 comments on commit b45be50

Please sign in to comment.