Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:humhub/humhub into develop
- Loading branch information
Showing
18 changed files
with
288 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...ected/humhub/modules/notification/migrations/m240422_162959_new_is_untouched_settings.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
use humhub\modules\content\models\ContentContainerSetting; | ||
use yii\db\Expression; | ||
use yii\db\Migration; | ||
use yii\db\Query; | ||
|
||
/** | ||
* Class m240422_162959_new_is_untouched_settings | ||
*/ | ||
class m240422_162959_new_is_untouched_settings extends Migration | ||
{ | ||
/** | ||
* Inserts new rows into the `content_container_setting` table to add the "is_touched_settings" | ||
* setting for the "notification" module where the "name" is "notification.like_email" which was | ||
* previously used to know if the setting was modified by the user or not | ||
* | ||
* {@inheritdoc} | ||
*/ | ||
public function safeUp() | ||
{ | ||
$rows = (new Query()) | ||
->select([ | ||
"module_id", | ||
"contentcontainer_id", | ||
new Expression("'is_touched_settings' as name"), | ||
new Expression("'1' as value"), | ||
]) | ||
->from(ContentContainerSetting::tableName()) | ||
->where([ | ||
'name' => 'notification.like_email', | ||
'module_id' => 'notification', | ||
]) | ||
->all(); | ||
|
||
$query = Yii::$app->db->createCommand() | ||
->batchInsert( | ||
ContentContainerSetting::tableName(), | ||
['module_id', 'contentcontainer_id', 'name', 'value'], | ||
$rows, | ||
); | ||
|
||
$query->execute(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeDown() | ||
{ | ||
echo "m240422_162959_new_is_untouched_settings cannot be reverted.\n"; | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
protected/humhub/modules/user/migrations/m240423_170311_profile_checkbox_list_field.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
use humhub\modules\user\models\fieldtype\CheckboxList; | ||
use humhub\modules\user\models\fieldtype\Select; | ||
use humhub\modules\user\models\ProfileField; | ||
use yii\db\Migration; | ||
use yii\helpers\Json; | ||
|
||
/** | ||
* Class m240423_170311_profile_checkbox_list_field | ||
*/ | ||
class m240423_170311_profile_checkbox_list_field extends Migration | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeUp() | ||
{ | ||
$fields = ProfileField::find() | ||
->where(['IN', 'field_type_class', [CheckboxList::class, Select::class]]); | ||
|
||
foreach ($fields->all() as $field) { | ||
/* @var ProfileField $field */ | ||
$fixedConfig = $this->getFixedProfileFieldConfig($field); | ||
if ($fixedConfig !== null) { | ||
$field->field_type_config = $fixedConfig; | ||
$field->save(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeDown() | ||
{ | ||
echo "m240423_170311_profile_checkbox_list_field cannot be reverted.\n"; | ||
return false; | ||
} | ||
|
||
private function getFixedProfileFieldConfig(ProfileField $field): ?string | ||
{ | ||
$config = Json::decode($field->field_type_config); | ||
|
||
if (!isset($config['options']) || $config['options'] === '') { | ||
return null; | ||
} | ||
|
||
$keyType = $field->field_type_class === Select::class ? 'index' : 'value'; | ||
$fixedOptions = []; | ||
$index = 0; | ||
$fixed = false; | ||
foreach (preg_split('/[\r\n]+/', $config['options']) as $option) { | ||
if (strpos($option, '=>') === false) { | ||
// Fix an option without a Key | ||
$fixed = true; | ||
$fixedOptions[] = ($keyType === 'index' ? $index++ : trim($option)) . '=>' . $option; | ||
} else { | ||
// Leave a correct option as is | ||
$fixedOptions[] = $option; | ||
} | ||
} | ||
|
||
if ($fixed === false) { | ||
return null; | ||
} | ||
|
||
$config['options'] = implode("\r\n", $fixedOptions); | ||
|
||
return Json::encode($config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.