Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -1,20 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter: Start a new conversion
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage convert
|
||||
* @since 21 Jan 2015
|
||||
*/
|
||||
|
||||
namespace IPS\convert\modules\admin\manage;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* create
|
||||
* Create new conversion session
|
||||
*/
|
||||
class _create extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
@@ -22,8 +35,15 @@ class _create extends \IPS\Dispatcher\Controller
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if ( \IPS\DEMO_MODE === TRUE )
|
||||
{
|
||||
\IPS\Output::i()->error( 'demo_mode_function_blocked', '2V391/3', 403, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->responsive = FALSE;
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'create_manage' );
|
||||
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'convert.css' ) );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -38,87 +58,34 @@ class _create extends \IPS\Dispatcher\Controller
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'convert_start' );
|
||||
|
||||
/* Let's call on the wizard to make some magic */
|
||||
\IPS\Output::i()->output = new \IPS\Helpers\Wizard( array(
|
||||
'convert_start_application' => array( $this, '_stepOne' ),
|
||||
'convert_start_source_software' => array( $this, '_stepTwo' ),
|
||||
'convert_start_database_details' => array( $this, '_stepThree' ),
|
||||
\IPS\Output::i()->output = (string) new \IPS\Helpers\Wizard( array(
|
||||
'convert_start_source_software' => array( $this, '_chooseSoftware' ),
|
||||
'convert_start_application' => array( $this, '_chooseApplications' ),
|
||||
'convert_start_database_details' => array( $this, '_setDatabaseDetails' ),
|
||||
'convert_start_conversion_details' => array( $this, '_setConversionDetails' ),
|
||||
), \IPS\Http\Url::internal( 'app=convert&module=manage&controller=create' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* First step of conversion
|
||||
* Choose what software you want to convert from
|
||||
*
|
||||
* @return void
|
||||
* @param array $data Wizard data from previous steps
|
||||
* @return \IPS\Helpers\Form|array
|
||||
*/
|
||||
public function _stepOne( $data )
|
||||
{
|
||||
foreach( \IPS\Application::applications() AS $app )
|
||||
{
|
||||
if ( \IPS\Member::loggedIn()->language()->checkKeyExists( "{$app->directory}_node_select" ) )
|
||||
{
|
||||
\IPS\member::loggedIn()->language()->words["__app_{$app->directory}"] = \IPS\Member::loggedIn()->language()->addToStack( "{$app->directory}_node_select" );
|
||||
}
|
||||
}
|
||||
|
||||
/* Have we done any conversions yet? */
|
||||
$appCount = \IPS\Db::i()->select( 'COUNT(*)', 'convert_apps', array( "parent=?", 0 ) )->first();
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'convert_application', 'select_source' );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'convert_start_application', NULL, TRUE, array( 'class' => 'IPS\\Application', 'subnodes' => FALSE, 'permissionCheck' => function( $node ) use ( $appCount )
|
||||
{
|
||||
foreach( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/convert/sources/Library' ) AS $file )
|
||||
{
|
||||
if ( ucwords( $node->directory ) === str_replace( '.php', '', $file->getFilename() ) )
|
||||
{
|
||||
$hasFile = FALSE;
|
||||
/* Only show the node if there is a converter available */
|
||||
foreach( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/convert/sources/Software/' . ucwords( $node->directory ) ) AS $softwareFile )
|
||||
{
|
||||
if( mb_substr( $softwareFile->getFilename(), -3 ) === 'php' )
|
||||
{
|
||||
$hasFile = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ( $node->directory === 'core' OR $appCount > 0 ) and $hasFile )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
} ) ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
return array( 'convert_start_application' => $values['convert_start_application']->directory );
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Second step of conversion
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function _stepTwo( $data )
|
||||
public function _chooseSoftware( $data )
|
||||
{
|
||||
$options = array();
|
||||
foreach( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/convert/sources/Software/' . ucwords( $data['convert_start_application'] ) ) AS $file )
|
||||
foreach( \IPS\convert\Software::software()['core'] AS $key => $classname )
|
||||
{
|
||||
$classname = 'IPS\\convert\\Software\\' . ucwords( $data['convert_start_application'] ) . '\\' . ucwords( str_replace( '.php', '', $file->getFilename() ) );
|
||||
if ( class_exists( $classname ) AND $classname::canConvert() !== NULL )
|
||||
{
|
||||
$options[ $classname::softwareKey() ] = $classname::softwareName();
|
||||
}
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'convert_source_software', 'enter_database_details' );
|
||||
$form = new \IPS\Helpers\Form( 'convert_source_software', 'choose_what_to_convert' );
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'convert_start_source_software', NULL, TRUE, array( 'options' => $options ) ) );
|
||||
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
return $values;
|
||||
@@ -128,56 +95,100 @@ class _create extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Third step of conversion
|
||||
* Choose which applications to convert
|
||||
*
|
||||
* @return void
|
||||
* @param array $data Wizard data from previous steps
|
||||
* @return \IPS\Helpers\Form|array
|
||||
*/
|
||||
public function _stepThree( $data )
|
||||
public function _chooseApplications( $data )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'convert_database_details', 'start_conversion' );
|
||||
$classname = 'IPS\\convert\\Software\\' . ucwords( $data['convert_start_application'] ) . '\\' . ucwords( $data['convert_start_source_software'] );
|
||||
/* Figure out what converter libraries we have for the selected application */
|
||||
$software = $data['convert_start_source_software'];
|
||||
$applications = array( 'core' => \IPS\Member::loggedIn()->language()->addToStack( 'core_node_select' ) );
|
||||
|
||||
if ( !is_null( $classname::parents() ) AND is_array( $classname::parents() ) )
|
||||
foreach( \IPS\convert\Library::libraries() AS $key => $class )
|
||||
{
|
||||
/* Do we have any available parents? */
|
||||
$where = array();
|
||||
$options = array();
|
||||
foreach( $classname::parents() AS $app => $sw )
|
||||
/* Check app is installed and enabled */
|
||||
if( !\IPS\Application::appIsEnabled( $key ) )
|
||||
{
|
||||
foreach( $sw AS $key )
|
||||
{
|
||||
$where[] = array( 'sw=? AND app_key=? AND finished=?', $app, $key, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
foreach( \IPS\Db::i()->select( '*', 'convert_apps', $where ) AS $row )
|
||||
{
|
||||
$name = explode( '_', $row['name'] );
|
||||
$parentClassname = 'IPS\\convert\\Software\\' . ucwords( $name[0] ) . '\\' . ucwords( $name[1] );
|
||||
$options[$row['app_id']] = $parentClassname::softwareName();
|
||||
}
|
||||
}
|
||||
catch( \Exception $e ) {}
|
||||
|
||||
/* If we have any possible parents, lets add a select menu */
|
||||
if ( count( $options ) > 0 )
|
||||
{
|
||||
$form->addHeader( 'convert_start_select_parent' );
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'convert_start_parent', NULL, FALSE, array( 'options' => $options ) ) );
|
||||
$form->addHeader( 'convert_start_or_database' );
|
||||
continue;
|
||||
}
|
||||
|
||||
/* This software class requires a parent, but we don't have any that have been converted */
|
||||
elseif( $classname::requiresParent() )
|
||||
foreach( \IPS\convert\Software::software()[ $key ] AS $softwareKey => $softwareClass )
|
||||
{
|
||||
\IPS\Output::i()->error( 'convert_no_applicable_parent', '4V346/1' );
|
||||
if( $softwareKey == $software )
|
||||
{
|
||||
$applications[ $key ] = \IPS\Member::loggedIn()->language()->addToStack( $key . '_node_select' );
|
||||
}
|
||||
elseif( isset( $softwareClass::parents()['core'] ) )
|
||||
{
|
||||
if( \in_array( $software, $softwareClass::parents()['core'] ) )
|
||||
{
|
||||
$applications[ $key . '_' . $softwareKey ] = \IPS\Member::loggedIn()->language()->get( $key . '_node_select' ) . ' - ' . $softwareClass::softwareName();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $classname::getPreConversionInformation() !== NULL )
|
||||
|
||||
/* Don't select the 'extra' converters */
|
||||
$preSelected = $applications;
|
||||
array_walk( $preSelected, function( $value, $key ) use( &$preSelected ) {
|
||||
if( mb_stristr( $key, '_' ) )
|
||||
{
|
||||
unset( $preSelected[ $key ] );
|
||||
}
|
||||
});
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'convert_application', 'enter_database_details' );
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'choose_what_to_convert', array_keys( $preSelected ), FALSE, array( 'options' => $applications, 'disabled' => array( 'core' ) ) ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack( $classname::getPreConversionInformation() ), '', FALSE );
|
||||
/* Core is required, and it was disabled on the form, so make sure it's in the array just to prevent people breaking stuff intentionally */
|
||||
if( !\in_array( 'core', $values['choose_what_to_convert'] ) )
|
||||
{
|
||||
$values['choose_what_to_convert'][] = 'core';
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow the admin to supply the needed details
|
||||
*
|
||||
* @param array $data Wizard data from previous steps
|
||||
* @return \IPS\Helpers\Form|array
|
||||
*/
|
||||
public function _setDatabaseDetails( $data )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'convert_database_details', 'enter_conversion_details' );
|
||||
|
||||
$usePrefix = NULL;
|
||||
|
||||
foreach( $data['choose_what_to_convert'] as $application )
|
||||
{
|
||||
if( mb_stristr( $application, '_' ) )
|
||||
{
|
||||
$converter = explode( '_', $application );
|
||||
$classname = \IPS\convert\Software::software()[ $converter[0] ] [ $converter[1] ];
|
||||
}
|
||||
else
|
||||
{
|
||||
$classname = \IPS\convert\Software::software()[ $application ] [ mb_strtolower( $data['convert_start_source_software'] ) ];
|
||||
}
|
||||
|
||||
if ( $classname::getPreConversionInformation() !== NULL )
|
||||
{
|
||||
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack( $classname::getPreConversionInformation() ), '', FALSE );
|
||||
}
|
||||
|
||||
if( $application == 'core' )
|
||||
{
|
||||
$usePrefix = $classname::usesPrefix();
|
||||
}
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'convert_start_database_host', NULL, FALSE ) );
|
||||
@@ -187,7 +198,7 @@ class _create extends \IPS\Dispatcher\Controller
|
||||
$form->add( new \IPS\Helpers\Form\Password( 'convert_start_database_pass', NULL, FALSE ) );
|
||||
|
||||
/* If the source software doesn't use a prefix, then we should not ask for one to avoid confusion. */
|
||||
if ( $classname::usesPrefix() )
|
||||
if ( $usePrefix )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'convert_start_database_prefix', NULL, FALSE ) );
|
||||
}
|
||||
@@ -196,32 +207,11 @@ class _create extends \IPS\Dispatcher\Controller
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* Did we select a parent but no DB details? */
|
||||
if (
|
||||
isset( $values['convert_start_parent'] ) AND
|
||||
( !isset( $values['convert_start_database_host'] ) || empty($values['convert_start_database_host']) ) AND
|
||||
( !isset( $values['convert_start_database_name'] ) || empty($values['convert_start_database_name']) ) AND
|
||||
( !isset( $values['convert_start_database_user'] ) || empty($values['convert_start_database_user']) ) AND
|
||||
( !isset( $values['convert_start_database_pass'] ) || empty($values['convert_start_database_pass']) ) AND
|
||||
( !isset( $values['convert_start_database_prefix'] ) || empty($values['convert_start_database_prefix']) ) AND
|
||||
( !isset( $values['convert_start_database_charset'] ) || empty($values['convert_start_database_charset']) )
|
||||
)
|
||||
{
|
||||
/* We did - load the parent app and store the DB details for that */
|
||||
$parentApp = \IPS\convert\App::load( $values['convert_start_parent'] );
|
||||
$values['convert_start_database_host'] = $parentApp->db_host;
|
||||
$values['convert_start_database_port'] = $parentApp->db_port;
|
||||
$values['convert_start_database_name'] = $parentApp->db_db;
|
||||
$values['convert_start_database_user'] = $parentApp->db_user;
|
||||
$values['convert_start_database_pass'] = $parentApp->db_pass;
|
||||
$values['convert_start_database_prefix'] = $parentApp->db_prefix;
|
||||
$values['convert_start_database_charset'] = $parentApp->db_charset;
|
||||
}
|
||||
|
||||
/* Start the app object */
|
||||
/* Start the (core) app object */
|
||||
$app = new \IPS\convert\App;
|
||||
$app->sw = $data['convert_start_application'];
|
||||
$app->sw = 'core';
|
||||
$app->app_key = $data['convert_start_source_software'];
|
||||
$app->parent = 0;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -246,14 +236,15 @@ class _create extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
|
||||
$db = \IPS\Db::i( 'convertertest', $connectionSettings );
|
||||
$db->checkConnection();
|
||||
|
||||
/* Now test the charset */
|
||||
if ( $values['convert_start_database_charset'] AND !in_array( $values['convert_start_database_charset'], array( 'utf8', 'utf8mb4' ) ) )
|
||||
if ( $values['convert_start_database_charset'] AND !\in_array( $values['convert_start_database_charset'], array( 'utf8', 'utf8mb4' ) ) )
|
||||
{
|
||||
/* Get all db charsets and make sure the one we entered is valid */
|
||||
$charsets = \IPS\convert\Software::getDatabaseCharsets( $db );
|
||||
|
||||
if ( !in_array( mb_strtolower( $values['convert_start_database_charset'] ), $charsets ) )
|
||||
if ( !\in_array( mb_strtolower( $values['convert_start_database_charset'] ), $charsets ) )
|
||||
{
|
||||
throw new \InvalidArgumentException( 'invalid_charset' );
|
||||
}
|
||||
@@ -261,30 +252,54 @@ class _create extends \IPS\Dispatcher\Controller
|
||||
$db->set_charset( $values['convert_start_database_charset'] );
|
||||
}
|
||||
|
||||
/* Try to verify that the db prefix is correct */
|
||||
$appClassName = $app->getSource( FALSE, FALSE );
|
||||
$canConvert = $appClassName::canConvert();
|
||||
$appClass = new $appClassName( $app, FALSE );
|
||||
$appClass->db = $db;
|
||||
$appsToCheck = array( $app );
|
||||
|
||||
$testAgainst = array_shift( $canConvert );
|
||||
foreach( $data['choose_what_to_convert'] as $application )
|
||||
{
|
||||
$childApp = new \IPS\convert\App;
|
||||
|
||||
/* We specifically use CountRows to test this, canConvert() may contain references to tables that do not exist..
|
||||
* ..This is for the row count look up.
|
||||
*/
|
||||
try
|
||||
{
|
||||
$appClass->countRows( $testAgainst['table'] );
|
||||
if( mb_stristr( $application, '_' ) )
|
||||
{
|
||||
$converter = explode( '_', $application );
|
||||
$childApp->sw = $converter[0];
|
||||
$childApp->app_key = $converter[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$childApp->sw = $application;
|
||||
$childApp->app_key = $data['convert_start_source_software'];
|
||||
}
|
||||
|
||||
$appsToCheck[] = $childApp;
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
|
||||
foreach( $appsToCheck as $appToCheck )
|
||||
{
|
||||
throw new \InvalidArgumentException( 'invalid_prefix' );
|
||||
}
|
||||
/* Can't find the table */
|
||||
catch( \IPS\convert\Exception $e )
|
||||
{
|
||||
$form->error = $e->getMessage();
|
||||
return $form;
|
||||
/* Try to verify that the db prefix is correct */
|
||||
$appClassName = $appToCheck->getSource( FALSE, FALSE );
|
||||
$canConvert = $appClassName::canConvert();
|
||||
$appClass = new $appClassName( $appToCheck, FALSE );
|
||||
$appClass->db = $db;
|
||||
|
||||
$testAgainst = array_shift( $canConvert );
|
||||
|
||||
/* We specifically use CountRows to test this, canConvert() may contain references to tables that do not exist..
|
||||
* ..This is for the row count look up.
|
||||
*/
|
||||
try
|
||||
{
|
||||
$appClass->countRows( $testAgainst['table'] );
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
throw new \InvalidArgumentException( 'invalid_prefix' );
|
||||
}
|
||||
/* Can't find the table */
|
||||
catch( \IPS\convert\Exception $e )
|
||||
{
|
||||
$form->error = $e->getMessage();
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( \InvalidArgumentException $e )
|
||||
@@ -309,26 +324,7 @@ class _create extends \IPS\Dispatcher\Controller
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack('convert_cant_connect_db');
|
||||
return $form;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$appExists = \IPS\convert\App::load( $data['convert_start_application'] . '_' . $data['convert_start_source_software'], 'name' );
|
||||
$app->name = $data['convert_start_application'] . '_' . $data['convert_start_source_software'] . '_' . time();
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
$app->name = $data['convert_start_application'] . '_' . $data['convert_start_source_software'];
|
||||
}
|
||||
|
||||
if ( isset( $values['convert_start_parent'] ) )
|
||||
{
|
||||
$app->parent = $values['convert_start_parent'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$app->parent = 0;
|
||||
}
|
||||
|
||||
|
||||
$app->db_host = $values['convert_start_database_host'];
|
||||
$app->db_port = $values['convert_start_database_port'];
|
||||
$app->db_db = $values['convert_start_database_name'];
|
||||
@@ -357,9 +353,203 @@ class _create extends \IPS\Dispatcher\Controller
|
||||
|
||||
$app->save();
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&id={$app->app_id}" ) );
|
||||
/* Now save the child applications */
|
||||
foreach( $data['choose_what_to_convert'] as $application )
|
||||
{
|
||||
if( $application == 'core' )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$childApp = clone $app;
|
||||
$childApp->parent = $app->app_id;
|
||||
|
||||
if( mb_stristr( $application, '_' ) )
|
||||
{
|
||||
$converter = explode( '_', $application );
|
||||
$childApp->sw = $converter[0];
|
||||
$childApp->app_key = $converter[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$childApp->sw = $application;
|
||||
}
|
||||
|
||||
$childApp->save();
|
||||
}
|
||||
|
||||
$values['_app_parent'] = $app->app_id;
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow the admin to supply the needed details
|
||||
*
|
||||
* @param array $data Wizard data from previous steps
|
||||
* @return \IPS\Helpers\Form
|
||||
*/
|
||||
public function _setConversionDetails( $data )
|
||||
{
|
||||
/* We may be coming here from a previously incomplete conversion setup...detect and set the parent app ID appropriately */
|
||||
if( ( !isset( $data['_app_parent'] ) OR !$data['_app_parent'] ) AND isset( \IPS\Request::i()->id ) )
|
||||
{
|
||||
$data['_app_parent'] = \IPS\Request::i()->id;
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'convert_other_details', 'start_conversion' );
|
||||
|
||||
try
|
||||
{
|
||||
$parentApplication = \IPS\convert\App::load( $data['_app_parent'] );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'conversion_app_not_found', '3V391/1', 404, '' );
|
||||
}
|
||||
|
||||
$this->_addConversionApplication( $parentApplication, $form );
|
||||
|
||||
foreach( $parentApplication->children() as $childApplication )
|
||||
{
|
||||
$this->_addConversionApplication( $childApplication, $form );
|
||||
}
|
||||
|
||||
if( $values = $form->values() )
|
||||
{
|
||||
/* We know the core/parent app is fine, but any child apps that don't have 'more_info' should be deleted as they cannot be converted */
|
||||
foreach( $parentApplication->children() as $childApplication )
|
||||
{
|
||||
if( !\count( $childApplication->_session['more_info'] ) )
|
||||
{
|
||||
$childApplication->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/* We have already saved our custom configuration, so now we can head off to the races */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&id={$data['_app_parent']}" ) );
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add form elements for the specified application to the form
|
||||
*
|
||||
* @param \IPS\convert\App $app Conversion application
|
||||
* @param \IPS\Helpers\Form $form Form object
|
||||
* @return void
|
||||
*/
|
||||
protected function _addConversionApplication( $app, &$form )
|
||||
{
|
||||
$softwareClass = $app->getSource();
|
||||
$libraryClass = $softwareClass->getLibrary();
|
||||
|
||||
/* Add a nice little header to the form */
|
||||
$form->addHeader( \IPS\Member::loggedIn()->language()->addToStack( 'converting_x_to_x', FALSE, array( 'sprintf' => array( $softwareClass::softwareName(), \IPS\Application::load( $app->sw )->_title ) ) ) );
|
||||
|
||||
/* Now fetch the details about this application we are converting so we can build the appropriate form elements */
|
||||
try
|
||||
{
|
||||
$menuRows = \IPS\convert\modules\admin\manage\convert::getMenuRows( $softwareClass, TRUE, TRUE );
|
||||
}
|
||||
catch( \IPS\Convert\Exception $e )
|
||||
{
|
||||
$form->addMessage( 'nothing_convertable_found', 'ipsMessage ipsMessage_warning', TRUE );
|
||||
return;
|
||||
}
|
||||
|
||||
/* Does this converter have settings that can be converted? */
|
||||
if ( $softwareClass::canConvertSettings() !== FALSE )
|
||||
{
|
||||
$settings = array();
|
||||
|
||||
foreach( $softwareClass->settingsMapList() as $key => $setting )
|
||||
{
|
||||
$value = $setting['value'];
|
||||
if ( \is_bool( ( $setting['value'] ) ) )
|
||||
{
|
||||
$value = $setting['value'] === TRUE ? 'On' : 'Off';
|
||||
}
|
||||
|
||||
$settings[ $setting['our_key'] ] = new \IPS\Helpers\Form\Checkbox( $setting['our_key'], TRUE, FALSE, array( 'label' => $value ), NULL, NULL, NULL, $setting['our_key'] );
|
||||
}
|
||||
|
||||
/* Add a nice little header to the form */
|
||||
$form->addHeader( 'convert_settings' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'convert_settings', TRUE, TRUE, array( 'togglesOn' => array_keys( $settings ) ) ) );
|
||||
|
||||
foreach( $settings as $settingFormField )
|
||||
{
|
||||
$form->add( $settingFormField );
|
||||
}
|
||||
|
||||
/* Did we just submit? If so save our configuration */
|
||||
if( $values = $form->values() )
|
||||
{
|
||||
$values = array_filter( $values, function( $key ) use ( $settings ) { return $key == 'convert_settings' OR \in_array( $key, array_keys( $settings ) ); }, ARRAY_FILTER_USE_KEY );
|
||||
|
||||
$app->saveMoreInfo( 'convertSettings', $values );
|
||||
}
|
||||
}
|
||||
|
||||
/* Now build the menu rows... */
|
||||
foreach( $menuRows as $row )
|
||||
{
|
||||
/* Determine if this step has any extra configuration questions */
|
||||
$formElements = array();
|
||||
|
||||
if ( \in_array( $row['step_method'], $softwareClass::checkConf() ) )
|
||||
{
|
||||
$getMoreInfo = $softwareClass->getMoreInfo( $row['step_method'] );
|
||||
if ( \is_array( $getMoreInfo ) AND \count( $getMoreInfo ) )
|
||||
{
|
||||
/* Show the 'more info' fields */
|
||||
foreach( $getMoreInfo as $key => $input )
|
||||
{
|
||||
$fieldClass = $input['field_class'];
|
||||
$formElements[ $key ] = new $fieldClass( $key, $input['field_default'], $input['field_required'], $input['field_extra'], isset( $input['field_validation'] ) ? $input['field_validation'] : NULL, NULL, NULL, $key );
|
||||
if ( $input['field_hint'] !== NULL )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words[ $key . '_desc' ] = $input['field_hint'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form->addHeader( $row['step_title'] );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( $row['step_title'], TRUE, TRUE, array( 'togglesOn' => array_keys( $formElements ) ) ) );
|
||||
|
||||
if( \count( $formElements ) )
|
||||
{
|
||||
foreach( $formElements as $key => $element )
|
||||
{
|
||||
$form->add( $element );
|
||||
}
|
||||
}
|
||||
|
||||
/* Did we just submit? If so save our configuration */
|
||||
if( $values = $form->values() )
|
||||
{
|
||||
$values = array_filter( $values, function( $key ) use ( $formElements, $row ) { return $key == $row['step_title'] OR \in_array( $key, array_keys( $formElements ) ); }, ARRAY_FILTER_USE_KEY );
|
||||
|
||||
$app->saveMoreInfo( $row['step_method'], $values );
|
||||
}
|
||||
}
|
||||
|
||||
/* If there was nothing to convert, show an appropriate message */
|
||||
if( $softwareClass::canConvertSettings() === FALSE AND !\count( $menuRows ) )
|
||||
{
|
||||
$form->addMessage( 'nothing_convertable_found', 'ipsMessage ipsMessage_warning', TRUE );
|
||||
}
|
||||
|
||||
/* If there is a message to show, go ahead and show it */
|
||||
if( $postConversionMessage = $libraryClass->getPostConversionInformation() )
|
||||
{
|
||||
$form->addMessage( $postConversionMessage, 'ipsMessage ipsMessage_info', FALSE );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user