| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCommunity\App\Hooks\Handlers; |
| 4 |
|
| 5 |
use FluentCommunity\App\Services\Helper; |
| 6 |
use FluentCommunity\Framework\Foundation\Application; |
| 7 |
use FluentCommunity\Database\DBMigrator; |
| 8 |
use FluentCommunity\App\Models\SpaceGroup; |
| 9 |
|
| 10 |
class ActivationHandler |
| 11 |
{ |
| 12 |
protected $app = null; |
| 13 |
|
| 14 |
public function __construct(Application $app) |
| 15 |
{ |
| 16 |
$this->app = $app; |
| 17 |
} |
| 18 |
|
| 19 |
public function handle($network_wide = false) |
| 20 |
{ |
| 21 |
DBMigrator::run($network_wide); |
| 22 |
update_option('fluent_community_db_version', FLUENT_COMMUNITY_DB_VERSION, 'no'); |
| 23 |
|
| 24 |
// We may need to register the action schedulers here |
| 25 |
if (!\as_next_scheduled_action('fluent_community_scheduled_hour_jobs')) { |
| 26 |
\as_schedule_recurring_action(time(), 3600, 'fluent_community_scheduled_hour_jobs', [], 'fluent-community', true); |
| 27 |
} |
| 28 |
|
| 29 |
if (!\as_next_scheduled_action('fluent_community_daily_jobs')) { |
| 30 |
\as_schedule_recurring_action(time(), 86400, 'fluent_community_daily_jobs', [], 'fluent-community', true); |
| 31 |
} |
| 32 |
|
| 33 |
$slug = Helper::getPortalSlug(); |
| 34 |
add_rewrite_rule('^' . $slug . '/?$', 'index.php?fcom_route=portal_home', 'top'); // For /hooks |
| 35 |
add_rewrite_rule('^' . $slug . '/(.+)/?', 'index.php?fcom_route=$matches[1]', 'top'); |
| 36 |
// flush rewrite rules |
| 37 |
flush_rewrite_rules(true); |
| 38 |
|
| 39 |
// remove the default WordPress templates caching |
| 40 |
wp_cache_delete( 'wp_get_global_stylesheet', 'theme_json' ); |
| 41 |
wp_cache_delete( 'wp_get_theme_data_template_parts', 'theme_json' ); |
| 42 |
} |
| 43 |
|
| 44 |
public function maybeCreateDefaultSpaceGroup() |
| 45 |
{ |
| 46 |
$exist = SpaceGroup::query()->exists(); |
| 47 |
if ($exist) { |
| 48 |
return false; |
| 49 |
} |
| 50 |
|
| 51 |
$defaultData = [ |
| 52 |
'title' => 'Get Started', |
| 53 |
'slug' => 'get-started', |
| 54 |
'serial' => 1, |
| 55 |
'description' => 'This is the default menu group. Please update the title and description.', |
| 56 |
'settings' => [ |
| 57 |
'hide_members' => 'no', |
| 58 |
'always_show_spaces' => 'yes' |
| 59 |
] |
| 60 |
]; |
| 61 |
|
| 62 |
return SpaceGroup::create($defaultData); |
| 63 |
} |
| 64 |
} |
| 65 |
|