Skip to content

Commit

Permalink
Flarum 1.0 update (#28)
Browse files Browse the repository at this point in the history
* Update for Flarum 1.0

* Add clear cache message after an import
  • Loading branch information
clarkwinkelmann authored May 29, 2021
1 parent 5ed8cec commit 287de96
Show file tree
Hide file tree
Showing 22 changed files with 551 additions and 338 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019-2020 FriendsOfFlarum
Copyright (c) 2019-2021 FriendsOfFlarum
Copyright (c) 2017-2019 Flagrow

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}
],
"require": {
"flarum/core": ">=0.1.0-beta.16 <0.1.0-beta.17",
"flarum/core": "^1.0",
"symfony/yaml": "^5.0"
},
"replace": {
Expand Down
2 changes: 1 addition & 1 deletion js/dist/admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/admin.js.map

Large diffs are not rendered by default.

821 changes: 511 additions & 310 deletions js/package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"private": true,
"name": "@fof/linguist",
"dependencies": {
"flarum-webpack-config": "0.1.0-beta.10",
"webpack": "^4.0.0",
"webpack-cli": "^3.0.7"
"flarum-webpack-config": "^1.0",
"webpack": "^4.0",
"webpack-cli": "^3.0"
},
"scripts": {
"dev": "webpack --mode development --watch",
"build": "webpack --mode production"
},
"devDependencies": {
"flarum": "0.1.0-beta.16"
"flarum": "^0.1.0-beta.16"
}
}
2 changes: 1 addition & 1 deletion js/src/admin/components/StringLocale.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import app from 'flarum/app';
import app from 'flarum/admin/app';
import ItemList from 'flarum/common/utils/ItemList';
import Button from 'flarum/common/components/Button';
import highlightMithril from '../utils/highlightMithril';
Expand Down
2 changes: 1 addition & 1 deletion js/src/admin/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import app from 'flarum/app';
import app from 'flarum/admin/app';
import StringKey from './models/StringKey';
import TextString from './models/TextString';
import LinguistPage from './pages/LinguistPage';
Expand Down
2 changes: 1 addition & 1 deletion js/src/admin/pages/CoveragePage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import app from 'flarum/app';
import app from 'flarum/admin/app';
import Button from 'flarum/common/components/Button';
import icon from 'flarum/common/helpers/icon';
import localesAsArray from '../utils/localesAsArray';
Expand Down
2 changes: 1 addition & 1 deletion js/src/admin/pages/ExportPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import app from 'flarum/app';
import app from 'flarum/admin/app';
import Select from 'flarum/common/components/Select';
import Switch from 'flarum/common/components/Switch';
import LinkButton from 'flarum/common/components/LinkButton';
Expand Down
2 changes: 1 addition & 1 deletion js/src/admin/pages/ImportPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import app from 'flarum/app';
import app from 'flarum/admin/app';
import Button from 'flarum/common/components/Button';
import Select from 'flarum/common/components/Select';
import Switch from 'flarum/common/components/Switch';
Expand Down
2 changes: 1 addition & 1 deletion js/src/admin/pages/LinguistPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import app from 'flarum/app';
import app from 'flarum/admin/app';
import ExtensionPage from 'flarum/admin/components/ExtensionPage';
import LoadingIndicator from 'flarum/common/components/LoadingIndicator';
import StringsPage from './StringsPage';
Expand Down
2 changes: 1 addition & 1 deletion js/src/admin/pages/StringsPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import app from 'flarum/app';
import app from 'flarum/admin/app';
import Button from 'flarum/common/components/Button';
import Dropdown from 'flarum/common/components/Dropdown';
import Select from 'flarum/common/components/Select';
Expand Down
2 changes: 1 addition & 1 deletion js/src/admin/utils/frontendLabel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import app from 'flarum/app';
import app from 'flarum/admin/app';

export default function (frontend) {
const translation = app.translator.translations['fof-linguist.admin.known-frontend.' + frontend];
Expand Down
2 changes: 1 addition & 1 deletion js/src/admin/utils/localesAsArray.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import app from 'flarum/app';
import app from 'flarum/admin/app';

export default function () {
let locales = [];
Expand Down
2 changes: 1 addition & 1 deletion js/src/admin/utils/namespaceLabel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import app from 'flarum/app';
import app from 'flarum/admin/app';

export default function (namespace) {
const translation = app.translator.translations['fof-linguist.admin.known-namespace.' + namespace];
Expand Down
12 changes: 12 additions & 0 deletions src/Api/Controllers/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace FoF\Linguist\Api\Controllers;

use Flarum\Foundation\ValidationException;
use FoF\Linguist\Repositories\StringRepository;
use FoF\Linguist\TextString;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
Expand All @@ -15,6 +16,13 @@

class ImportController implements RequestHandlerInterface
{
protected $repository;

public function __construct(StringRepository $repository)
{
$this->repository = $repository;
}

public function handle(ServerRequestInterface $request): ResponseInterface
{
$request->getAttribute('actor')->assertAdmin();
Expand Down Expand Up @@ -81,6 +89,10 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$totalImported++;
}

if ($totalImported > 0) {
$this->repository->cacheShouldBeCleared();
}

return new JsonResponse([
'imported' => $totalImported,
'ignored' => $totalIgnored,
Expand Down
6 changes: 3 additions & 3 deletions src/Api/Serializers/StringKeySerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

class StringKeySerializer extends AbstractSerializer
{
public function getType($model)
public function getType($model): string
{
return 'fof-linguist-string-key';
}

public function getId($model)
public function getId($model): string
{
return Arr::get($model, 'key');
}

protected function getDefaultAttributes($model)
protected function getDefaultAttributes($model): array
{
return $model;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Serializers/StringSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

class StringSerializer extends AbstractSerializer
{
public function getType($model)
public function getType($model): string
{
return 'fof-linguist-string';
}

protected function getDefaultAttributes($model)
protected function getDefaultAttributes($model): array
{
return $model->toArray();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Repositories/StringRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function delete(TextString $string)
$this->cacheShouldBeCleared();
}

protected function cacheShouldBeCleared()
public function cacheShouldBeCleared()
{
// This flags lets the frontend know it should suggest to the user to clear the cache
$this->settings->set('fof.linguist.should-clear-cache', '1');
Expand Down
6 changes: 3 additions & 3 deletions src/TranslationLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ class TranslationLock
{
protected static $apply = true;

public static function stopLoadingTranslations()
public static function stopLoadingTranslations(): void
{
self::$apply = false;
}

public static function continueLoadingTranslations()
public static function continueLoadingTranslations(): void
{
self::$apply = true;
}

public static function shouldLoadTranslations()
public static function shouldLoadTranslations(): bool
{
return self::$apply;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Validators/StringValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class StringValidator extends AbstractValidator
{
protected function getRules()
protected function getRules(): array
{
return [
'key' => 'required|string',
Expand Down

0 comments on commit 287de96

Please sign in to comment.