-
Notifications
You must be signed in to change notification settings - Fork 1
/
pressbooks-multi-institution.php
46 lines (39 loc) · 1.6 KB
/
pressbooks-multi-institution.php
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
<?php
/**
* Plugin Name: Pressbooks Shared Network
* Plugin URI: https://github.com/pressbooks/pressbooks-multi-institution
* Requires at least: 6.5
* Requires Plugins: pressbooks
* Description: Tools for managing Pressbooks networks shared by multiple institutions
* x-release-please-start-version
* Version: 1.1.0
* x-release-please-end
* Author: Pressbooks (Book Oven Inc.)
* Author URI: https://pressbooks.org
* Requires PHP: 8.1
* Pressbooks tested up to: 6.16.0
* Text Domain: pressbooks-multi-institution
* License: GPL v3 or later
* Network: True
*/
use PressbooksMultiInstitution\Bootstrap;
use PressbooksMultiInstitution\Commands\ResetDbSchemaCommand;
use PressbooksMultiInstitution\Database\Migration;
use PressbooksMultiInstitution\Models\InstitutionUser;
use PressbooksMultiInstitution\Services\PermissionsManager;
register_activation_hook(__FILE__, [Migration::class, 'migrate']);
register_activation_hook(__FILE__, function () {
$managerIds = InstitutionUser::query()->managers()->pluck('user_id')->toArray();
PermissionsManager::syncRestrictedUsers($managerIds, []);
});
register_deactivation_hook(__FILE__, [PermissionsManager::class, 'revokeInstitutionalManagersPrivileges']);
add_action('plugins_loaded', [Bootstrap::class, 'run']);
add_action('cli_init', function () {
if (! defined('WP_CLI')) {
return;
}
WP_CLI::add_command('pb:reset-db-schema', function ($args, $assoc_args) {
(new ResetDbSchemaCommand)->__invoke($args, $assoc_args) ?
WP_CLI::success('Database successfully reset.') : WP_CLI::error('Error resetting database.');
});
});