Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@

namespace Joomla\Component\MigrateToJoomla\Administrator\Controller;

use Joomla\CMS\Event\AbstractEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Session\Session;
use Joomla\Component\MigrateToJoomla\Administrator\Helper\LogHelper;
use Joomla\Component\MigrateToJoomla\Administrator\Event\MigrationStatusEvent;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -37,22 +35,26 @@ class ProgressController extends BaseController

public function ajax()
{
if (!Session::checkToken('get')) {
/**if (!Session::checkToken('get')) {
$this->app->setHeader('status', 403, true);
$this->app->sendHeaders();
echo Text::_('JINVALID_TOKEN_NOTICE');
$this->app->close();
}
}**/

$input = $this->appinput;
$input = $this->app->getInput();
$field = $input->getArray(['name' => ''])['name'];
$key = $input->getArray(['key' => ''])['key'];

$this->callPluginMethod($field, $key);

$default[] = [];
$event = $this->callPluginMethod($field, $key);

$response = Factory::getSession()->get('migratetojoomla.ajaxresponse', $default);
if ($event->getStatus() == 1) {
$response = ['status' => 'success'];
} elseif ($event->getStatus() == 0) {
$response = ['status' => 'error'];
} elseif ($event->getStatus() == -1) {
$response = ['status' => 'notice'];
}

echo json_encode($response);
$this->app->close();
Expand All @@ -69,22 +71,26 @@ public function callPluginMethod($field = '', $key = null)
return;
}

if ($field == "end") {
LogHelper::writeLogFileOfSession();
}

$options = [
'format' => '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}',
'text_file' => 'wordpress-to-joomla.php',
];
Log::addLogger($options);

if ($field == "media") {
// calling media plugin method
PluginHelper::importPlugin('migratetojoomla', 'mediadownload');

$event = AbstractEvent::create(
$event = new MigrationStatusEvent(
'migratetojoomla_downloadmedia',
[
'subject' => $this,
'formname' => 'com_migratetojoomla.parameter',
]
);

Factory::getApplication()->triggerEvent('migratetojoomla_downloadmedia', $event);
$this->app->getDispatcher()->dispatch('migratetojoomla_downloadmedia', $event);
} else {
// calling framework specific plugin method for database migration

Expand All @@ -96,7 +102,7 @@ public function callPluginMethod($field = '', $key = null)

$eventname = "migratetojoomla_" . $field;

$event = AbstractEvent::create(
$event = new MigrationStatusEvent(
$eventname,
[
'subject' => $this,
Expand All @@ -105,8 +111,14 @@ public function callPluginMethod($field = '', $key = null)
'field' => $field,
]
);

Factory::getApplication()->triggerEvent($eventname, $event);
$event->setLastID((int) $this->app->getUserState('com_migratetojoomla.migrate.lastKey', 0));
$this->app->getDispatcher()->dispatch($eventname, $event);
$this->app->setUserState('com_migratetojoomla.migrate.lastKey', $event->getLastID());
if ($event->getStatus() == -1) {
$this->app->setUserState('com_migratetojoomla.migrate.lastKey', 0);
}
}

return $event;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage com_migratetojoomla
*
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\MigrateToJoomla\Administrator\Event;

use Joomla\Event\AbstractEvent;
use Joomla\Registry\Registry;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Class for Content event.
* Example:
* new ContentPrepareEvent('onEventName', ['context' => 'com_example.example', 'subject' => $contentObject, 'params' => $params, 'page' => $pageNum]);
*
* @since 5.0.0
*/
class MigrationStatusEvent extends AbstractEvent
{
protected $lastID;
protected $status;
protected $error;

public function getLastID(): int
{
return (int) $this->lastID;
}

public function setLastID(int $lastID)
{
$this->lastID = $lastID;
}

public function getStatus()
{
return $this->status;
}

public function setStatus(int $status)
{
$this->status = $status;
}

public function setError($error)
{
$this->error = $error;
}

public function getError()
{
return $this->error;
}

/**
* Setter for the subject argument.
*
* @param object $value The value to set
*
* @return object
*
* @since 5.0.0
*/
protected function onSetSubject(object $value): object
{
return $value;
}

/**
* Setter for the params argument.
*
* @param Registry $value The value to set
*
* @return Registry
*
* @since 5.0.0
*/
protected function onSetParams($value): Registry
{
// This is for b/c compatibility, because some extensions pass a mixed types
if (!$value instanceof Registry) {
$value = new Registry($value);

// @TODO: In 6.0 throw an exception
@trigger_error(
\sprintf('The "params" attribute for the event "%s" must be type of Registry. In 6.0 it will throw an exception', $this->getName()),
E_USER_DEPRECATED
);
}

return $value;
}

/**
* Setter for the page argument.
*
* @param ?int $value The value to set
*
* @return ?int
*
* @since 5.0.0
*/
protected function onSetPage(?int $value): ?int
{
return $value;
}

/**
* Getter for the item argument.
*
* @return object
*
* @since 5.0.0
*/
public function getItem(): object
{
return $this->arguments['subject'];
}

/**
* Getter for the item argument.
*
* @return Registry
*
* @since 5.0.0
*/
public function getParams(): Registry
{
return $this->arguments['params'];
}

/**
* Getter for the page argument.
*
* @return ?int
*
* @since 5.0.0
*/
public function getPage(): ?int
{
return $this->arguments['page'];
}

public function offsetSet(mixed $offset, mixed $value): void
{
// TODO: Implement offsetSet() method.
}

public function offsetUnset(mixed $offset): void
{
// TODO: Implement offsetUnset() method.
}
}

This file was deleted.

Loading