65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
<?php
|
|
|
|
use humhub\components\Migration;
|
|
|
|
class m260401_201000_set_rescues_default_home extends Migration
|
|
{
|
|
public function safeUp()
|
|
{
|
|
$rows = (new \yii\db\Query())
|
|
->select(['contentcontainer_id', 'url', 'guid'])
|
|
->from('space')
|
|
->where(['in', 'contentcontainer_id', (new \yii\db\Query())
|
|
->select('contentcontainer_id')
|
|
->from('rescue_space_profile')])
|
|
->all($this->db);
|
|
|
|
foreach ($rows as $row) {
|
|
$spacePath = trim((string)($row['url'] ?? ''));
|
|
if ($spacePath === '') {
|
|
$spacePath = trim((string)($row['guid'] ?? ''));
|
|
}
|
|
|
|
if ($spacePath === '') {
|
|
continue;
|
|
}
|
|
|
|
$homeUrl = '/s/' . $spacePath . '/rescues';
|
|
$contentContainerId = (int)$row['contentcontainer_id'];
|
|
|
|
$this->upsert('contentcontainer_setting', [
|
|
'module_id' => 'space',
|
|
'contentcontainer_id' => $contentContainerId,
|
|
'name' => 'indexUrl',
|
|
'value' => $homeUrl,
|
|
], [
|
|
'value' => $homeUrl,
|
|
]);
|
|
|
|
$this->upsert('contentcontainer_setting', [
|
|
'module_id' => 'space',
|
|
'contentcontainer_id' => $contentContainerId,
|
|
'name' => 'indexGuestUrl',
|
|
'value' => $homeUrl,
|
|
], [
|
|
'value' => $homeUrl,
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function safeDown()
|
|
{
|
|
$this->delete('contentcontainer_setting', [
|
|
'and',
|
|
['module_id' => 'space', 'name' => 'indexUrl'],
|
|
['like', 'value', '/s/%/rescues', false],
|
|
]);
|
|
|
|
$this->delete('contentcontainer_setting', [
|
|
'and',
|
|
['module_id' => 'space', 'name' => 'indexGuestUrl'],
|
|
['like', 'value', '/s/%/rescues', false],
|
|
]);
|
|
}
|
|
}
|