This repository has been archived by the owner on Aug 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34c2598
commit 772163c
Showing
13 changed files
with
321 additions
and
293 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace Ambercal\SettingsTransfer; | ||
|
||
use Elgg\PluginBootstrap; | ||
|
||
class Bootstrap extends PluginBootstrap { | ||
|
||
/** | ||
* Executed during 'plugins_load', 'system' event | ||
* | ||
* Allows the plugin to require additional files, as well as configure services prior to booting the plugin | ||
* | ||
* @return void | ||
*/ | ||
public function load() { | ||
// TODO: Implement load() method. | ||
} | ||
|
||
/** | ||
* Executed during 'plugins_boot:before', 'system' event | ||
* | ||
* Allows the plugin to register handlers for 'plugins_boot', 'system' and 'init', 'system' events, | ||
* as well as implement boot time logic | ||
* | ||
* @return void | ||
*/ | ||
public function boot() { | ||
// TODO: Implement boot() method. | ||
} | ||
|
||
/** | ||
* Executed during 'init', 'system' event | ||
* | ||
* Allows the plugin to implement business logic and register all other handlers | ||
* | ||
* @return void | ||
*/ | ||
public function init() { | ||
elgg_register_plugin_hook_handler('register', 'menu:page', SetupAdminMenu::class); | ||
} | ||
|
||
/** | ||
* Executed during 'ready', 'system' event | ||
* | ||
* Allows the plugin to implement logic after all plugins are initialized | ||
* | ||
* @return void | ||
*/ | ||
public function ready() { | ||
// TODO: Implement ready() method. | ||
} | ||
|
||
/** | ||
* Executed during 'shutdown', 'system' event | ||
* | ||
* Allows the plugin to implement logic during shutdown | ||
* | ||
* @return void | ||
*/ | ||
public function shutdown() { | ||
// TODO: Implement shutdown() method. | ||
} | ||
|
||
/** | ||
* Executed when plugin is activated, after 'activate', 'plugin' event and before activate.php is included | ||
* | ||
* @return void | ||
*/ | ||
public function activate() { | ||
// TODO: Implement activate() method. | ||
} | ||
|
||
/** | ||
* Executed when plugin is deactivated, after 'deactivate', 'plugin' event and before deactivate.php is included | ||
* | ||
* @return void | ||
*/ | ||
public function deactivate() { | ||
// TODO: Implement deactivate() method. | ||
} | ||
|
||
/** | ||
* Registered as handler for 'upgrade', 'system' event | ||
* | ||
* Allows the plugin to implement logic during system upgrade | ||
* | ||
* @return void | ||
*/ | ||
public function upgrade() { | ||
// TODO: Implement upgrade() method. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Ambercal\SettingsTransfer; | ||
|
||
use Elgg\Request; | ||
use Symfony\Component\HttpFoundation\BinaryFileResponse; | ||
|
||
class ExportSettings { | ||
|
||
public function __invoke(Request $request) { | ||
$options = $request->getParam('options', []); | ||
|
||
$export_options = []; | ||
foreach ($options as $option) { | ||
$export_options[$option] = true; | ||
} | ||
|
||
$dt = new \DateTime('now'); | ||
$filename = implode('-', ['settings', $dt->format('Y-m-d-H-i')]); | ||
|
||
$svc = new TransferService(); | ||
$export = $svc->export($export_options); | ||
$json = json_encode($export); | ||
|
||
$dir = elgg_get_data_path() . 'settings_transfer/'; | ||
if (!is_dir($dir)) { | ||
mkdir($dir, 0755, true); | ||
} | ||
|
||
$filepath = "{$dir}${filename}.json"; | ||
|
||
$fh = fopen($filepath, 'w'); | ||
fwrite($fh, $json); | ||
fclose($fh); | ||
|
||
$response = BinaryFileResponse::create($filepath, 200, [ | ||
'Content-Type' => 'application/json; charset=UTF-8', | ||
], true, 'attachment'); | ||
|
||
$response->send(); | ||
|
||
exit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* | ||
*/ | ||
|
||
namespace Ambercal\SettingsTransfer; | ||
|
||
|
||
use Elgg\Request; | ||
use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
|
||
class ImportSettings { | ||
|
||
public function __invoke(Request $request) { | ||
$file = elgg_get_uploaded_file('json'); | ||
|
||
if ($file instanceof UploadedFile && $file->isValid()) { | ||
$contents = @file_get_contents($file->getPathname()); | ||
$json = @json_decode($contents, true); | ||
} | ||
|
||
if (empty($json)) { | ||
$error = elgg_echo('admin:plugin_settings_transfer:upload:invalid_json'); | ||
|
||
return elgg_error_response($error); | ||
} | ||
|
||
$options = $request->getParam('options', []); | ||
|
||
$import_options = []; | ||
|
||
foreach ($options as $option) { | ||
$import_options[$option] = true; | ||
} | ||
|
||
$svc = new TransferService(); | ||
$errors = $svc->import($json, $import_options); | ||
|
||
if ($errors) { | ||
return elgg_error_response(elgg_echo('admin:plugin_settings_transfer:import:error', [$errors])); | ||
} | ||
|
||
elgg_flush_caches(); | ||
|
||
return elgg_ok_response('', elgg_echo('admin:plugin_settings_transfer:import:success')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Ambercal\SettingsTransfer; | ||
|
||
use Elgg\HooksRegistrationService\Hook; | ||
|
||
class SetupAdminMenu { | ||
public function __invoke(Hook $hook) { | ||
$menu = $hook->getValue(); | ||
/* @var $menu \Elgg\Collections\Collection */ | ||
|
||
$menu->add(\ElggMenuItem::factory([ | ||
'name' => 'settings_transfer', | ||
'text' => elgg_echo('admin:plugin_settings_transfer'), | ||
'section' => 'develop', | ||
'context' => ['admin'], | ||
])); | ||
|
||
$menu->add(\ElggMenuItem::factory([ | ||
'name' => 'settings_transfer:import', | ||
'text' => elgg_echo('admin:plugin_settings_transfer:import'), | ||
'href' => 'admin/plugin_settings_transfer/import', | ||
'section' => 'develop', | ||
'context' => ['admin'], | ||
'parent_name' => 'settings_transfer', | ||
])); | ||
|
||
$menu->add(\ElggMenuItem::factory([ | ||
'name' => 'settings_transfer:export', | ||
'text' => elgg_echo('admin:plugin_settings_transfer:export'), | ||
'href' => 'admin/plugin_settings_transfer/export', | ||
'section' => 'develop', | ||
'context' => ['admin'], | ||
'parent_name' => 'settings_transfer', | ||
])); | ||
|
||
return $menu; | ||
} | ||
} |
Oops, something went wrong.