-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathEnableI18n.class.php
More file actions
55 lines (48 loc) · 1.61 KB
/
EnableI18n.class.php
File metadata and controls
55 lines (48 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace wcf\command\article;
use wcf\data\article\Article;
use wcf\data\article\ArticleAction;
use wcf\data\article\content\ArticleContentAction;
use wcf\system\language\LanguageFactory;
use wcf\system\version\VersionTracker;
/**
* Converts a monolingual article to a multilingual.
*
* @author Marcel Werk
* @copyright 2001-2025 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
*/
final class EnableI18n
{
public function __construct(
private readonly Article $article,
) {}
public function __invoke(): void
{
$articleContent = $this->article->getArticleContent();
$data = [];
foreach (LanguageFactory::getInstance()->getLanguages() as $language) {
$data[$language->languageID] = [
'title' => $articleContent->title,
'teaser' => $articleContent->teaser,
'content' => $articleContent->content,
'imageID' => $articleContent->imageID ?: null,
'teaserImageID' => $articleContent->teaserImageID ?: null,
];
}
$action = new ArticleAction([$this->article], 'update', [
'content' => $data,
'data' => [
'isMultilingual' => 1,
],
]);
$action->executeAction();
$action = new ArticleContentAction([$articleContent], 'delete');
$action->executeAction();
VersionTracker::getInstance()->reset(
'com.woltlab.wcf.article',
$this->article->articleID
);
}
}