Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

Commit

Permalink
feat(releases): upgrade for Elgg 3
Browse files Browse the repository at this point in the history
  • Loading branch information
hypeJunction committed Jun 5, 2019
1 parent 34c2598 commit 772163c
Show file tree
Hide file tree
Showing 13 changed files with 321 additions and 293 deletions.
24 changes: 0 additions & 24 deletions actions/plugins/settings/export.php

This file was deleted.

39 changes: 0 additions & 39 deletions actions/plugins/settings/import.php

This file was deleted.

93 changes: 93 additions & 0 deletions classes/Ambercal/SettingsTransfer/Bootstrap.php
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.
}
}
44 changes: 44 additions & 0 deletions classes/Ambercal/SettingsTransfer/ExportSettings.php
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;
}
}
47 changes: 47 additions & 0 deletions classes/Ambercal/SettingsTransfer/ImportSettings.php
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'));
}
}
39 changes: 39 additions & 0 deletions classes/Ambercal/SettingsTransfer/SetupAdminMenu.php
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;
}
}
Loading

0 comments on commit 772163c

Please sign in to comment.