Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing allowedExtensions in MLContent #608

Merged
merged 5 commits into from
Oct 2, 2020
Merged
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
2 changes: 2 additions & 0 deletions classes/MLContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
class MLContent extends MLCmsObject
{
protected $allowedExtensions = ['htm', 'txt', 'md'];

public static function findLocale($locale, $page)
{
if (!$page->exists) {
Expand Down
6 changes: 4 additions & 2 deletions models/MessageImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MessageImport extends ImportModel
public function importData($results, $sessionKey = null)
{
$codeName = MessageExport::CODE_COLUMN_NAME;
$defaultName = Message::DEFAULT_LOCALE;

foreach ($results as $index => $result) {
try {
Expand All @@ -44,8 +45,9 @@ public function importData($results, $sessionKey = null)
// Create empty array, if $message is new
$message->message_data = $message->message_data ?: [];

if (!isset($message->message_data[Message::DEFAULT_LOCALE])) {
$result[Message::DEFAULT_LOCALE] = $code;
if (!isset($message->message_data[$defaultName])) {
$default = (isset($result[$defaultName]) && !empty($result[$defaultName])) ? $result[$defaultName] : $code;
$result[$defaultName] = $default;
}

$message->message_data = array_merge($message->message_data, $result);
Expand Down
7 changes: 0 additions & 7 deletions tests/unit/behaviors/TranslatablePageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ public function setUp(): void
$resolver = new Resolver(['theme1' => $datasource]);
$resolver->setDefaultDatasource('theme1');
Model::setDatasourceResolver($resolver);

TranslatablePage::extend(function($page) {
if (!$page->isClassExtendedWith('RainLab\Translate\Behaviors\TranslatablePage')) {
$page->addDynamicProperty('translatable', ['title']);
$page->extendClassWith('RainLab\Translate\Behaviors\TranslatablePage');
}
LukeTowers marked this conversation as resolved.
Show resolved Hide resolved
});
}

public function tearDown(): void
Expand Down
71 changes: 41 additions & 30 deletions updates/builder_table_update_rainlab_translate_locales.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
<?php namespace RainLab\Translate\Updates;

use RainLab\Translate\Models\Locale;
use Schema;
use October\Rain\Database\Updates\Migration;

class BuilderTableUpdateRainlabTranslateLocales extends Migration
{
public function up()
{
Schema::table('rainlab_translate_locales', function($table)
{
$table->integer('sort_order')->default(0);
});

$locales = Locale::all();
foreach($locales as $locale) {
$locale->sort_order = $locale->id;
$locale->save();
}
}

public function down()
{
Schema::table('rainlab_translate_locales', function($table)
{
$table->dropColumn('sort_order');
});
}
}
<?php namespace RainLab\Translate\Updates;

use RainLab\Translate\Models\Locale;
use Schema;
use October\Rain\Database\Updates\Migration;

class BuilderTableUpdateRainlabTranslateLocales extends Migration
{
const TABLE_NAME = 'rainlab_translate_locales';

public function up()
{
if (!Schema::hasTable(self::TABLE_NAME)) {
return;
}

if (!Schema::hasColumn(self::TABLE_NAME, 'found')) {
Schema::table(self::TABLE_NAME, function($table)
{
$table->integer('sort_order')->default(0);
});
}

$locales = Locale::all();
foreach($locales as $locale) {
$locale->sort_order = $locale->id;
$locale->save();
}
}

public function down()
{
if (!Schema::hasTable(self::TABLE_NAME)) {
return;
}

if (Schema::hasColumn(self::TABLE_NAME, 'found')) {
Schema::dropColumn(['sort_order']);
}
}
}
29 changes: 20 additions & 9 deletions updates/update_messages_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,30 @@

class UpdateMessagesTable extends Migration
{
const TABLE_NAME = 'rainlab_translate_messages';

public function up()
{
Schema::table('rainlab_translate_messages', function($table)
{
$table->boolean('found')->default(1);
});
if (!Schema::hasTable(self::TABLE_NAME)) {
return;
}

if (!Schema::hasColumn(self::TABLE_NAME, 'found')) {
Schema::table(self::TABLE_NAME, function($table)
{
$table->boolean('found')->default(1);
});
}
}

public function down()
{
Schema::table('rainlab_translate_messages', function($table)
{
$table->dropColumn('found');
});
if (!Schema::hasTable(self::TABLE_NAME)) {
return;
}

if (Schema::hasColumn(self::TABLE_NAME, 'found')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@mjauvin just as an FYI, I know it doesn't really matter since migration files should probably never be extended, but I would prefer we always use static:: over self:: unless there's a really good reason to use self::. It's a better practice to keep since that will provide the most flexibility for developers looking to extend the code.

Schema::dropColumn(['found']);
}
}
}
}