Skip to content

Commit

Permalink
Update for Flarum beta 16
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkwinkelmann committed Mar 22, 2021
1 parent ea492b1 commit 60809cc
Show file tree
Hide file tree
Showing 9 changed files with 828 additions and 742 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Clark Winkelmann
Copyright (c) 2020-2021 Clark Winkelmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"type": "flarum-extension",
"license": "MIT",
"require": {
"flarum/core": ">=0.1.0-beta.15 <0.1.0-beta.16",
"flarum/core": ">=0.1.0-beta.16 <0.1.0-beta.17",
"ext-json": "*",
"fof/console": "^0.6.0"
"fof/console": "^0.7.0"
},
"authors": [
{
Expand All @@ -31,7 +31,7 @@
"extra": {
"flarum-extension": {
"title": "Popular Discussion",
"category": "discussion",
"category": "feature",
"icon": {
"name": "fas fa-fire",
"backgroundColor": "#684ba6",
Expand Down
18 changes: 1 addition & 17 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Flarum\Api\Serializer\ForumSerializer;
use Flarum\Discussion\Discussion;
use Flarum\Extend;
use Flarum\Settings\SettingsRepositoryInterface;

return [
(new Extend\Frontend('forum'))
Expand All @@ -30,22 +29,7 @@
}),

(new Extend\ApiSerializer(ForumSerializer::class))
->mutate(function () {
/**
* @var SettingsRepositoryInterface $settings
*/
$settings = app(SettingsRepositoryInterface::class);

// Only include the conditions if we are in Frontend mode
// The presence of the conditions will signal the frontend to use Frontend mode
if ($settings->get('clarkwinkelmann-popular-discussion-badge.mode') !== 'scheduler') {
return [
'popularDiscussionBadgeConditions' => json_decode($settings->get('clarkwinkelmann-popular-discussion-badge.conditions')),
];
}

return [];
}),
->attributes(ForumAttributes::class),

(new Extend\ServiceProvider())
->register(Providers\ConsoleProvider::class),
Expand Down
2 changes: 1 addition & 1 deletion js/dist/admin.js.map

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@clarkwinkelmann/flarum-ext-popular-discussion-badge",
"name": "@clarkwinkelmann/popular-discussion-badge",
"version": "0.0.0",
"private": true,
"dependencies": {
Expand Down
1,503 changes: 787 additions & 716 deletions js/yarn.lock

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions src/ForumAttributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace ClarkWinkelmann\PopularDiscussionBadge;

use Flarum\Settings\SettingsRepositoryInterface;

class ForumAttributes
{
protected $settings;

public function __construct(SettingsRepositoryInterface $settings)
{
$this->settings = $settings;
}

public function __invoke(): array
{
// Only include the conditions if we are in Frontend mode
// The presence of the conditions will signal the frontend to use Frontend mode
if ($this->settings->get('clarkwinkelmann-popular-discussion-badge.mode') !== 'scheduler') {
return [
'popularDiscussionBadgeConditions' => json_decode($this->settings->get('clarkwinkelmann-popular-discussion-badge.conditions')),
];
}

return [];
}
}
7 changes: 5 additions & 2 deletions src/Providers/ConsoleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ public function register()
define('ARTISAN_BINARY', 'flarum');
}

$settings = $this->app->make(SettingsRepositoryInterface::class);
/**
* @var $settings SettingsRepositoryInterface
*/
$settings = $this->container->make(SettingsRepositoryInterface::class);

if ($settings->get('clarkwinkelmann-popular-discussion-badge.mode') !== 'scheduler') {
return;
}

$frequency = $settings->get('clarkwinkelmann-popular-discussion-badge.scheduler_frequency', 'daily');

$this->app->resolving(Schedule::class, function (Schedule $schedule) use ($frequency) {
$this->container->resolving(Schedule::class, function (Schedule $schedule) use ($frequency) {
$builder = $schedule->command('clarkwinkelmann:popular-discussions');

switch ($frequency) {
Expand Down

0 comments on commit 60809cc

Please sign in to comment.