Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal #38

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
116 changes: 7 additions & 109 deletions src/administrator/components/com_migratetojoomla/forms/information.xml
Original file line number Diff line number Diff line change
@@ -1,111 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<field
name="mediaoptions"
type="list"
label="COM_MIGRATETOJOOMLA_SELECT_OPTION_FOR_MEDIA_LABEL"
description="COM_MIGRATETOJOOMLA_SELECT_OPTION_FOR_MEDIA_DESC"
class="form-select"
default="fs"
validate="options"
>
<option value="fs">COM_MIGRATETOJOOMLA_FS</option>
<!-- <option value="http">COM_MIGRATETOJOOMLA_HTTP</option>
<option value="ftp">COM_MIGRATETOJOOMLA_FTP</option> -->
</field>
<field
name="livewebsiteurl"
type="text"
showon="mediaoptions:http"
label="COM_MIGRATETOJOOMLA_HTTP_LINK_LABEL"
description="COM_MIGRATETOJOOMLA_HTTP_LINK_DESC"/>
<field
name="basedir"
type="text"
showon="mediaoptions:fs"
label="COM_MIGRATETOJOOMLA_WEBSITE_BASE_DIRECTORY_LABEL"
description="COM_MIGRATETOJOOMLA_WEBSITE_BASE_DIRECTORY_DESC"/>
<field
name="ftphost"
type="text"
showon="mediaoptions:ftp"
label="COM_MIGRATETOJOOMLA_FTP_HOST_LABEL"
description="COM_MIGRATETOJOOMLA_FTP_HOST_DESC"/>
<field
name="ftpport"
type="int"
showon="mediaoptions:ftp"
default="21"
label="COM_MIGRATETOJOOMLA_FTP_PORT_LABEL"
description="COM_MIGRATETOJOOMLA_FTP_PORT_DESC"/>
<field
name="ftpusername"
type="text"
showon="mediaoptions:ftp"
label="COM_MIGRATETOJOOMLA_FTP_USERNAME_LABEL"
description="COM_MIGRATETOJOOMLA_FTP_USERNAME_DESC"/>
<field
name="ftppassword"
type="password"
showon="mediaoptions:ftp"
label="COM_MIGRATETOJOOMLA_FTP_PASSWORD_LABEL"
description="COM_MIGRATETOJOOMLA_FTP_PASSWORD_DESC"/>
<field
name="ftpprotocoloptions"
type="list"
label="COM_MIGRATETOJOOMLA_FTP_PROTOCOL_LABEL"
class="form-select"
default="ftp"
showon="mediaoptions:ftp"
validate="options"
description="COM_MIGRATETOJOOMLA_FTP_PROTOCOL_DESC"
>
<option value="ftp">COM_MIGRATETOJOOMLA_FTP</option>
<option value="ftps">COM_MIGRATETOJOOMLA_FTPS</option>
<option value="sftp">COM_MIGRATETOJOOMLA_SFTP</option>
</field>
<field
name="ftpbasedir"
type="text"
showon="mediaoptions:ftp"
label="COM_MIGRATETOJOOMLA_FTP_BASE_DIR_LABEL"
description="COM_MIGRATETOJOOMLA_FTP_BASE_DIR_DESC"/>
<field
name="dbhostname"
type="text"
label="COM_MIGRATETOJOOMLA_DATABASE_HOSTNAME_LABEL"
description="COM_MIGRATETOJOOMLA_DATABASE_HOSTNAME_DESC"/>
<field
name="dbdriver"
type="text"
default="mysqli"
label="COM_MIGRATETOJOOMLA_DATABASE_DRIVER_LABEL"
description="COM_MIGRATETOJOOMLA_DATABASE_DRIVER_DESC"/>
<field
name="dbport"
type="int"
default='3306'
label="COM_MIGRATETOJOOMLA_DATABASE_PORT_LABEL"
description="COM_MIGRATETOJOOMLA_DATABASE_PORT_DESC"/>
<field
name="dbname"
type="text"
label="COM_MIGRATETOJOOMLA_DATABASE_NAME_LABEL"
description="COM_MIGRATETOJOOMLA_DATABASE_NAME_DESC"/>
<field
name="dbusername"
type="text"
label="COM_MIGRATETOJOOMLA_DATABASE_USERNAME_LABEL"
description="COM_MIGRATETOJOOMLA_DATABASE_USERNAME_DESC"/>
<field
name="dbpassword"
type="text"
default=""
label="COM_MIGRATETOJOOMLA_DATABASE_PASSWORD_LABEL"
description="COM_MIGRATETOJOOMLA_DATABASE_PASSWORD_DESC"/>
<field
name="dbtableprefix"
type="text"
label="COM_MIGRATETOJOOMLA_DATABASE_TABLE_PREFIX_LABEL"
description="COM_MIGRATETOJOOMLA_DATABASE_TABLE_PREFIX_DESC"/>
</form>
<fieldset name="general">
<field
name="type"
type="hidden"
/>
</fieldset>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,6 @@ COM_MIGRATETOJOOMLA_WORDPRESS="WordPress"
COM_MIGRATETOJOOMLA_WORDPRESS_FTP_PARAMETERS="WordPress ftp parameters"
COM_MIGRATETOJOOMLA_WORDPRESS_WEBSITE_PARAMETERS="WordPress Website Parameters"
COM_MIGRATETOJOOMLA_XML_DESCRIPTION="This component migrates websites from other platforms to Joomla."

COM_MIGRATETOJOOMLA_VIEW_MIGRATE_TITLE="Welcome to the Joomla Migrator"
COM_MIGRATETOJOOMLA_VIEW_MIGRATE_DESCRIPTION="Please first select the source CMS to migrate from towards this Joomla installation."
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Joomla\Component\MigrateToJoomla\Administrator\Controller;

use Joomla\CMS\Event\AbstractEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\Plugin\PluginHelper;
Expand Down Expand Up @@ -66,10 +65,9 @@ class InformationController extends FormController
public function storeFormAndPrevious()
{
$this->checkToken();
$app = Factory::getApplication();
$data = $this->input->post->get('jform', [], 'array');

$app->setUserState('com_migratetojoomla.information', $data);
$this->app->setUserState('com_migratetojoomla.information', $data);

$this->setRedirect(Route::_('index.php?option=com_migratetojoomla&view=migrate', false));
}
Expand All @@ -82,14 +80,13 @@ public function storeFormAndPrevious()
public function storeFormAndNext()
{
$this->checkToken();
$app = Factory::getApplication();
$data = $this->input->post->get('jform', [], 'array');

$this->checkMediaConnection(0);
$this->checkDatabaseConnection(0);
$app->setUserState('com_migratetojoomla.information', $data);
$this->app->setUserState('com_migratetojoomla.information', $data);

$this->setRedirect(Route::_('index.php?option=com_migratetojoomla&view=parameter', false));
$this->setRedirect(Route::_('index.php?option=com_migratetojoomla&view=check', false));
}

/**
Expand All @@ -101,12 +98,10 @@ public function checkMediaConnection()
{
$this->checkToken();

$app = Factory::getApplication();

$data = $this->input->post->get('jform', [], 'array');

// Store data in session
$app->setUserState('com_migratetojoomla.information', $data);
$this->app->setUserState('com_migratetojoomla.information', $data);

PluginHelper::importPlugin('migratetojoomla', 'mediadownload');

Expand All @@ -117,9 +112,9 @@ public function checkMediaConnection()
]
);

Factory::getApplication()->triggerEvent('migratetojoomla_testmediaconnection', $event);
$this->app->triggerEvent('migratetojoomla_testmediaconnection', $event);

$app->setUserState('com_migratetojoomla.information', $data);
$this->app->setUserState('com_migratetojoomla.information', $data);

$this->setRedirect(Route::_('index.php?option=com_migratetojoomla&view=information', false));
}
Expand All @@ -133,20 +128,19 @@ public function checkDatabaseConnection($msgshow = 1)
{
$this->checkToken();

$app = Factory::getApplication();
$data = $this->input->post->get('jform', [], 'array');

$session = Factory::getSession();
$session = $this->app->getSession();

if (self::setdatabase($this, $data)) {
$msgshow && $app->enqueueMessage(Text::_('COM_MIGRATETOJOOMLA_DATABASE_CONNECTION_SUCCESSFULLY'), 'success');
$msgshow && $this->app->enqueueMessage(Text::_('COM_MIGRATETOJOOMLA_DATABASE_CONNECTION_SUCCESSFULLY'), 'success');
$session->set('databaseconnectionresult', true);
} else {
$msgshow && $app->enqueueMessage(Text::_('COM_MIGRATETOJOOMLA_DATABASE_CONNECTION_UNSUCCESSFULLY'), 'error');
$msgshow && $this->app->enqueueMessage(Text::_('COM_MIGRATETOJOOMLA_DATABASE_CONNECTION_UNSUCCESSFULLY'), 'error');
$session->set('databaseconnectionresult', false);
}

$app->setUserState('com_migratetojoomla.information', $data);
$this->app->setUserState('com_migratetojoomla.information', $data);

$this->setRedirect(Route::_('index.php?option=com_migratetojoomla&view=information', false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace Joomla\Component\MigrateToJoomla\Administrator\Controller;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\FormController;

Expand All @@ -33,9 +32,8 @@ class LogController extends FormController
public function download()
{
$this->checkToken();
$app = Factory::getApplication();

$logFileName = @trim((Factory::getApplication()->getUserState('com_migratetojoomla.migrate', [])['framework'] . '')) . '-to-Joomla-migrate.txt';
$logFileName = @trim(($this->app->getUserState('com_migratetojoomla.migrate', [])['framework'] . '')) . '-to-Joomla-migrate.txt';

$headWithFileName = "Content-Disposition: attachment; filename=$logFileName";

Expand All @@ -49,7 +47,7 @@ public function download()

flush();

$app->close();
$this->app->close();
}

/**
Expand All @@ -59,16 +57,15 @@ public function download()
*/
public function echoRawLog()
{
$logfolder = JPATH_ADMINISTRATOR . '\components\com_migratetojoomla\logs\\';
$logfileName = @trim((Factory::getApplication()->getUserState('com_migratetojoomla.migrate', [])['framework'] . '')) . '-to-Joomla.log';
$logfolder = JPATH_ADMINISTRATOR . '/components/com_migratetojoomla/logs/';
$logfileName = @trim(($this->app->getUserState('com_migratetojoomla.migrate', [])['framework'] . '')) . '-to-Joomla.log';

$logFile = $logfolder . $logfileName;

$file = @fopen($logFile, 'r');

if ($file === false) {
$app = Factory::getApplication();
$app->enqueueMessage(Text::_('COM_MIGRATETOJOOMLA_ERROR_WHILE_DOWNLOAD_LOG'), 'danger');
$this->app->enqueueMessage(Text::_('COM_MIGRATETOJOOMLA_ERROR_WHILE_DOWNLOAD_LOG'), 'danger');
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace Joomla\Component\MigrateToJoomla\Administrator\Controller;

use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\Router\Route;

Expand All @@ -33,13 +32,12 @@ class MigrateController extends FormController
public function storeFormAndNext()
{
$this->checkToken();
$app = Factory::getApplication();
$data = $this->input->post->get('jform', [], 'array');

$session = Factory::getSession();
$session = $this->app->getSession();
$session->set('framework', $data['framework']);

$app->setUserState('com_migratetojoomla.migrate', $data);
$this->app->setUserState('com_migratetojoomla.migrate', $data);

$this->setRedirect(Route::_('index.php?option=com_migratetojoomla&view=information', false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ class ParameterController extends FormController
public function storeFormAndNext()
{
$this->checkToken();
$app = Factory::getApplication();
$data = $this->input->post->get('jform', [], 'array');

$app->setUserState('com_migratetojoomla.parameter', $data);
$this->app->setUserState('com_migratetojoomla.parameter', $data);

$this->setRedirect(Route::_('index.php?option=com_migratetojoomla&view=check', false));
}
Expand All @@ -49,13 +48,12 @@ public function storeFormAndNext()
public function storeFormAndPrevious()
{
$this->checkToken();
$app = Factory::getApplication();
$data = $this->input->post->get('jform', [], 'array');

$session = Factory::getSession();
$session->set('parameterformdata', $data);

$app->setUserState('com_migratetojoomla.parameter', $data);
$this->appsetUserState('com_migratetojoomla.parameter', $data);

$this->setRedirect(Route::_('index.php?option=com_migratetojoomla&view=information', false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function ajax()
echo Text::_('JINVALID_TOKEN_NOTICE');
$this->app->close();
}
$app = Factory::getApplication();
$input = $app->input;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2023 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\CMS\Event\AbstractImmutableEvent;
use Joomla\CMS\Event\Result\ResultAwareInterface;
use Joomla\CMS\Event\Result\ResultTypeMixedAware;

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

/**
* Class for onAjax... events
*
* @since 5.0.0
*/
class MigrationtypeEvent extends AbstractImmutableEvent implements ResultAwareInterface
{
use ResultTypeMixedAware;

/**
* Appends data to the result of the event.
*
* @param mixed $data What to add to the result.
*
* @return void
* @since 5.0.0
*/
public function addResult($data): void
{
$this->arguments['result'] = $this->arguments['result'] ?? [];
$this->arguments['result'][] = $data;
}

/**
* Update the result of the event.
*
* @param mixed $data What to add to the result.
*
* @return static
* @since 5.0.0
*/
public function updateEventResult($data): static
{
$this->arguments['result'] = $data;

return $this;
}

/**
* Get the event result.
*
* @return mixed
* @since 5.0.0
*/
public function getEventResult(): mixed
{
return $this->arguments['result'] ?? null;
}
}
Loading