Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+153 -128
View File
@@ -12,9 +12,34 @@
namespace IPS\convert\Library;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use Exception;
use IPS\convert\App;
use IPS\convert\Library;
use IPS\DateTime;
use IPS\Db;
use IPS\File;
use IPS\Http\url;
use IPS\Lang;
use IPS\Member;
use IPS\nexus\Gateway;
use IPS\nexus\Invoice;
use IPS\nexus\Money;
use IPS\nexus\Transaction;
use IPS\Settings;
use OutOfRangeException;
use UnderflowException;
use function count;
use function defined;
use function get_class;
use function in_array;
use function is_array;
use function is_null;
use function strtoupper;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
@@ -22,7 +47,7 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
* Invision Commerce (Nexus) Converter
* @note We must extend the Core Library here so we can access methods like convertAttachment, convertFollow, etc
*/
class _Nexus extends \IPS\convert\Library
class Nexus extends Library
{
/**
* @brief Application
@@ -48,7 +73,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_customer_fields',
'step_method' => 'convertNexusCustomerFields',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customer_fields' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_customer_fields' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array(),
@@ -58,7 +83,7 @@ class _Nexus extends \IPS\convert\Library
case 'convertNexusCustomers':
$dependencies = array();
if ( \in_array( 'convertNexusCustomerFields', $this->getConvertableItems() ) )
if ( in_array( 'convertNexusCustomerFields', $this->getConvertableItems() ) )
{
$dependencies[] = 'convertNexusCustomerFields';
}
@@ -66,7 +91,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_customers',
'step_method' => 'convertNexusCustomers',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customers' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_customers' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => $dependencies,
@@ -78,7 +103,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_customer_addresses',
'step_method' => 'convertNexusCustomerAddresses',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customer_addresses' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_customer_addresses' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers' ),
@@ -90,7 +115,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_customer_history',
'step_method' => 'convertNexusCustomerHistory',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'core_member_history', array( 'log_app=?', 'nexus' ) ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'core_member_history', array( 'log_app=?', 'nexus' ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers' ),
@@ -102,7 +127,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_alternate_contacts',
'step_method' => 'convertNexusAlternateContacts',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_alternate_contacts' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_alternate_contacts' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers' ),
@@ -114,7 +139,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_notes',
'step_method' => 'convertNexusNotes',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_notes' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_notes' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers' ),
@@ -126,7 +151,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_payment_methods',
'step_method' => 'convertNexusPaymentMethods',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_paymethods' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_paymethods' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array(),
@@ -138,7 +163,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_package_groups',
'step_method' => 'convertNexusPackageGroups',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_package_groups' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_package_groups' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array(),
@@ -150,7 +175,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_package_fields',
'step_method' => 'convertNexusPackageFields',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_package_fields' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_package_fields' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array(),
@@ -172,7 +197,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_packages',
'step_method' => 'convertNexusPackages',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_packages' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_packages' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'dependencies' => $dependencies,
@@ -185,7 +210,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_reviews',
'step_method' => 'convertNexusReviews',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_reviews' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_reviews' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array( 'convertNexusPackages' ),
@@ -198,7 +223,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_coupons',
'step_method' => 'convertNexusCoupons',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_coupons' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_coupons' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array( 'convertNexusPackages' ),
@@ -232,7 +257,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_invoices',
'step_method' => 'convertNexusInvoices',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_invoices' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_invoices' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => $dependencies,
@@ -255,7 +280,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_transactions',
'step_method' => 'convertNexusTransactions',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_transactions' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_transactions' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => $dependencies,
@@ -277,7 +302,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_purchases',
'step_method' => 'convertNexusPurchases',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_purchases' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => $dependencies,
@@ -289,7 +314,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_fraud_rules',
'step_method' => 'convertNexusFraudRules',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_fraud_rules' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_fraud_rules' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array(),
@@ -301,7 +326,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_support_departments',
'step_method' => 'convertNexusSupportDepartments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_departments' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_support_departments' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array( 'convertNexusPackages' ),
@@ -312,7 +337,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_support_fields',
'step_method' => 'convertNexusSupportFields',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_fields' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_support_fields' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array( 'convertNexusSupportDepartments' ),
@@ -324,7 +349,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_support_statuses',
'step_method' => 'convertNexusSupportStatuses',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_statuses' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_support_statuses' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array(),
@@ -336,7 +361,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_support_severities',
'step_method' => 'convertNexusSupportSeverities',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_severities' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_support_severities' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array( 'convertNexusSupportDepartments' ),
@@ -348,7 +373,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_support_stock_actions',
'step_method' => 'convertNexusSupportStockActions',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_stock_actions' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_support_stock_actions' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array( 'convertNexusSupportDepartments' ),
@@ -360,7 +385,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_support_requests',
'step_method' => 'convertNexusSupportRequests',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_requests' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_support_requests' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers', 'convertNexusSupportDepartments', 'convertNexusSupportFields' ),
@@ -373,7 +398,7 @@ class _Nexus extends \IPS\convert\Library
$return[ $k ] = array(
'step_title' => 'convert_nexus_support_replies',
'step_method' => 'convertNexusSupportReplies',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_replies' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'nexus_support_replies' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array( 'convertNexusSupportRequests' ),
@@ -411,7 +436,7 @@ class _Nexus extends \IPS\convert\Library
protected function truncate( $method )
{
$return = array();
$classname = \get_class( $this->software );
$classname = get_class( $this->software );
if( $classname::canConvert() === NULL )
{
@@ -427,7 +452,7 @@ class _Nexus extends \IPS\convert\Library
break;
case 'convertNexusCustomers':
$return['convertNexusCustomers'] = array( 'nexus_customers' => array( "member_id<>?", \IPS\Member::loggedIn()->member_id ) );
$return['convertNexusCustomers'] = array( 'nexus_customers' => array( "member_id<>?", Member::loggedIn()->member_id ) );
break;
case 'convertNexusCustomerAddresses':
@@ -555,7 +580,7 @@ class _Nexus extends \IPS\convert\Library
{
if ( !isset( $info['member_id'] ) )
{
$this->software->app->log( 'nexus_customer_missing_ids', __METHOD__, \IPS\convert\App::LOG_WARNING );
$this->software->app->log( 'nexus_customer_missing_ids', __METHOD__, App::LOG_WARNING );
return FALSE;
}
else
@@ -566,9 +591,9 @@ class _Nexus extends \IPS\convert\Library
{
$info['member_id'] = $this->software->app->getLink( $info['member_id'], 'core_members', TRUE );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$this->software->app->log( 'nexus_customer_missing_member', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['member_id'] );
$this->software->app->log( 'nexus_customer_missing_member', __METHOD__, App::LOG_WARNING, $info['member_id'] );
return FALSE;
}
}
@@ -590,7 +615,7 @@ class _Nexus extends \IPS\convert\Library
if ( isset( $info['cm_profiles'] ) )
{
if ( \is_array( $info['cm_profiles'] ) )
if ( is_array( $info['cm_profiles'] ) )
{
$info['cm_profiles'] = json_encode( $info['cm_profiles'] );
}
@@ -602,7 +627,7 @@ class _Nexus extends \IPS\convert\Library
$info = array_merge( $info, $this->_formatCustomerFields( $fields ) );
\IPS\Db::i()->replace( 'nexus_customers', $info );
Db::i()->replace( 'nexus_customers', $info );
$this->software->app->addLink( $info['member_id'], $sourceId, 'nexus_customers' );
return $info['member_id'];
@@ -619,7 +644,7 @@ class _Nexus extends \IPS\convert\Library
$return = array();
foreach( $fields as $key => $value )
{
if ( \is_array( $value ) )
if ( is_array( $value ) )
{
$value = json_encode( $value );
}
@@ -630,7 +655,7 @@ class _Nexus extends \IPS\convert\Library
$return['field_' . $id] = $value;
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
continue;
}
@@ -664,20 +689,20 @@ class _Nexus extends \IPS\convert\Library
{
if ( !isset( $info['code'] ) )
{
$this->software->app->log( 'nexus_currency_missing_code', __METHOD__, \IPS\convert\App::LOG_WARNING );
$this->software->app->log( 'nexus_currency_missing_code', __METHOD__, App::LOG_WARNING );
return FALSE;
}
/* Normalise the currency code */
$info['code'] = \strtoupper( $info['code'] );
$info['code'] = strtoupper( $info['code'] );
if ( !\in_array( $info['code'], $this->_allowedCurrencies ) )
if ( !in_array( $info['code'], $this->_allowedCurrencies ) )
{
$this->software->app->log( 'nexus_currency_not_allowed', __METHOD__, \IPS\convert\App::LOG_WARNING );
$this->software->app->log( 'nexus_currency_not_allowed', __METHOD__, App::LOG_WARNING );
return FALSE;
}
$currencies = json_decode( \IPS\Settings::i()->nexus_currency, TRUE );
$currencies = json_decode( Settings::i()->nexus_currency, TRUE );
/* Currencies are a little odd in that they don't really have a link */
if( isset( $currencies[ $info['code'] ] ) )
@@ -689,7 +714,7 @@ class _Nexus extends \IPS\convert\Library
$currencies[ $info['code'] ] = array();
/* save */
\IPS\Settings::i()->changeValues( array( 'nexus_currency' => json_encode( $currencies ) ) );
Settings::i()->changeValues( array( 'nexus_currency' => json_encode( $currencies ) ) );
return $info['code'];
}
@@ -714,21 +739,21 @@ class _Nexus extends \IPS\convert\Library
{
$info['note_member'] = $this->software->app->getLink( $info['note_member'], 'core_members', TRUE );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$this->software->app->log( "nexus_note_missing_member", __METHOD__, \IPS\convert\App::LOG_WARNING, ( $hasId ) ? $info['note_id'] : NULL );
$this->software->app->log( "nexus_note_missing_member", __METHOD__, App::LOG_WARNING, ( $hasId ) ? $info['note_id'] : NULL );
return FALSE;
}
}
else
{
$this->software->app->log( 'nexus_note_missing_member', __METHOD__, \IPS\convert\App::LOG_WARNING, ( $hasId ) ? $info['note_id'] : NULL );
$this->software->app->log( 'nexus_note_missing_member', __METHOD__, App::LOG_WARNING, ( $hasId ) ? $info['note_id'] : NULL );
return FALSE;
}
if ( empty( $info['note_text'] ) )
{
$this->software->app->log( 'nexus_note_missing_content', __METHOD__, \IPS\convert\App::LOG_WARNING, ( $hasId ) ? $info['note_id'] : NULL );
$this->software->app->log( 'nexus_note_missing_content', __METHOD__, App::LOG_WARNING, ( $hasId ) ? $info['note_id'] : NULL );
return FALSE;
}
@@ -738,7 +763,7 @@ class _Nexus extends \IPS\convert\Library
{
$info['note_author'] = $this->software->app->getLink( $info['note_author'], 'core_members', TRUE );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$info['note_author'] = 0;
}
@@ -750,7 +775,7 @@ class _Nexus extends \IPS\convert\Library
if ( isset( $info['note_date'] ) )
{
if ( $info['note_date'] instanceof \IPS\DateTime )
if ( $info['note_date'] instanceof DateTime )
{
$info['note_date'] = $info['note_date']->getTimestamp();
}
@@ -766,7 +791,7 @@ class _Nexus extends \IPS\convert\Library
unset( $info['note_id'] );
}
$inserted_id = \IPS\Db::i()->insert( 'nexus_notes', $info );
$inserted_id = Db::i()->insert( 'nexus_notes', $info );
if ( $hasId )
{
@@ -788,7 +813,7 @@ class _Nexus extends \IPS\convert\Library
{
if ( !isset( $info['pg_id'] ) )
{
$this->software->app->log( 'nexus_package_group_missing_ids', __METHOD__, \IPS\convert\App::LOG_WARNING );
$this->software->app->log( 'nexus_package_group_missing_ids', __METHOD__, App::LOG_WARNING );
return FALSE;
}
@@ -804,12 +829,12 @@ class _Nexus extends \IPS\convert\Library
if ( !isset( $info['pg_seo_name'] ) )
{
$info['pg_seo_name'] = \IPS\Http\Url::seoTitle( $name );
$info['pg_seo_name'] = Url::seoTitle( $name );
}
if ( !isset( $info['pg_position'] ) )
{
$position = \IPS\Db::i()->select( 'MAX(pg_position)', 'nexus_package_groups' )->first();
$position = Db::i()->select( 'MAX(pg_position)', 'nexus_package_groups' )->first();
$info['pg_position'] = $position + 1;
}
@@ -823,9 +848,9 @@ class _Nexus extends \IPS\convert\Library
$info['pg_parent'] = 0;
}
if ( isset( $info['pg_image'] ) AND ( !\is_null( $filepath ) OR !\is_null( $filedata ) ) )
if ( isset( $info['pg_image'] ) AND ( !is_null( $filepath ) OR !is_null( $filedata ) ) )
{
if ( \is_null( $filedata ) AND !\is_null( $filepath ) )
if ( is_null( $filedata ) AND !is_null( $filepath ) )
{
$filedata = @file_get_contents( rtrim( $filepath, '/' ) . '/' . $info['pg_image'] );
unset( $filepath );
@@ -835,10 +860,10 @@ class _Nexus extends \IPS\convert\Library
{
try
{
$file = \IPS\File::create( 'nexus_PackageGroups', $info['pg_image'], $filedata );
$file = File::create( 'nexus_PackageGroups', $info['pg_image'], $filedata );
$info['pg_image'] = (string) $file;
}
catch( \Exception $e )
catch( Exception $e )
{
$info['pg_image'] = '';
}
@@ -856,13 +881,13 @@ class _Nexus extends \IPS\convert\Library
$id = $info['pg_id'];
unset( $info['pg_id'] );
$insertedId = \IPS\Db::i()->insert( 'nexus_package_groups', $info );
$insertedId = Db::i()->insert( 'nexus_package_groups', $info );
$this->software->app->addLink( $insertedId, $id, 'nexus_package_groups' );
/* Custom Lang */
\IPS\Lang::saveCustom( 'nexus', "nexus_pgroup_{$insertedId}", $name );
Lang::saveCustom( 'nexus', "nexus_pgroup_{$insertedId}", $name );
\IPS\Db::i()->update( 'nexus_package_groups', array( 'pg_parent' => $insertedId ), array( "pg_conv_parent=?", $id ) );
Db::i()->update( 'nexus_package_groups', array( 'pg_parent' => $insertedId ), array( "pg_conv_parent=?", $id ) );
return $insertedId;
}
@@ -878,14 +903,14 @@ class _Nexus extends \IPS\convert\Library
/* !Required: ID */
if ( !isset( $info['m_id'] ) )
{
$this->software->app->log( 'nexus_payment_method_missing_id', __METHOD__, \IPS\convert\App::LOG_WARNING );
$this->software->app->log( 'nexus_payment_method_missing_id', __METHOD__, App::LOG_WARNING );
return FALSE;
}
/* !Required: Method */
if ( !isset( $info['m_gateway'] ) )
{
$this->software->app->log( 'nexus_payment_method_missing_gateway', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['m_id'] );
$this->software->app->log( 'nexus_payment_method_missing_gateway', __METHOD__, App::LOG_WARNING, $info['m_id'] );
return FALSE;
}
@@ -893,7 +918,7 @@ class _Nexus extends \IPS\convert\Library
if( $info['m_gateway'] === FALSE )
{
$this->software->app->log( 'nexus_payment_method_not_supported', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['m_id'] );
$this->software->app->log( 'nexus_payment_method_not_supported', __METHOD__, App::LOG_WARNING, $info['m_id'] );
return FALSE;
}
@@ -919,10 +944,10 @@ class _Nexus extends \IPS\convert\Library
unset( $info['m_id'], $info['m_name'] );
/* Save Product Data */
$insertedId = \IPS\Db::i()->insert( 'nexus_paymethods', $this->_getValues( $gateway, $info ) );
$insertedId = Db::i()->insert( 'nexus_paymethods', $this->_getValues( $gateway, $info ) );
/* Custom lang strings */
\IPS\Lang::saveCustom( 'nexus', "nexus_paymethod_{$insertedId}", $name );
Lang::saveCustom( 'nexus', "nexus_paymethod_{$insertedId}", $name );
/* Add Link */
$this->software->app->addLink( $insertedId, $originalId, 'nexus_payment_methods' );
@@ -942,7 +967,7 @@ class _Nexus extends \IPS\convert\Library
/* !Required: ID */
if ( !isset( $info['p_id'] ) )
{
$this->software->app->log( 'nexus_package_missing_id', __METHOD__, \IPS\convert\App::LOG_WARNING );
$this->software->app->log( 'nexus_package_missing_id', __METHOD__, App::LOG_WARNING );
return FALSE;
}
@@ -969,14 +994,14 @@ class _Nexus extends \IPS\convert\Library
/* !Required: Price */
if( !isset( $info['p_base_price'] ) )
{
$this->software->app->log( 'nexus_package_missing_price', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['p_id'] );
$this->software->app->log( 'nexus_package_missing_price', __METHOD__, App::LOG_WARNING, $info['p_id'] );
return FALSE;
}
/* !Required: Package Group */
if( !isset( $info['p_group'] ) )
{
$this->software->app->log( 'nexus_package_missing_group', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['p_id'] );
$this->software->app->log( 'nexus_package_missing_group', __METHOD__, App::LOG_WARNING, $info['p_id'] );
return FALSE;
}
$info['p_group'] = $this->software->app->getLink( $info['p_group'], 'nexus_package_groups' );
@@ -998,7 +1023,7 @@ class _Nexus extends \IPS\convert\Library
{
$newGroups[] = $this->software->app->getLink( $group, 'core_groups', TRUE );
}
catch( \OutOfRangeException $ex ) { }
catch( OutOfRangeException $ex ) { }
}, $newGroups );
$info['p_member_group'] = $info['p_member_group'];
@@ -1022,7 +1047,7 @@ class _Nexus extends \IPS\convert\Library
{
$newSecondaryGroups[] = $this->software->app->getLink( $group, 'core_groups', TRUE );
}
catch( \OutOfRangeException $ex ) { }
catch( OutOfRangeException $ex ) { }
}, $newSecondaryGroups );
}
@@ -1033,7 +1058,7 @@ class _Nexus extends \IPS\convert\Library
{
$info['p_associable'] = $this->software->app->getLink( $info['p_associable'], 'nexus_packages' );
}
catch( \OutOfRangeException $ex )
catch( OutOfRangeException $ex )
{
$info['conv_p_associable'] = $info['p_associable'];
unset( $info['p_associable'] );
@@ -1044,16 +1069,16 @@ class _Nexus extends \IPS\convert\Library
{
try
{
$position = \IPS\Db::i()->select( 'MAX(p_position)', 'nexus_packages' )->first();
$position = Db::i()->select( 'MAX(p_position)', 'nexus_packages' )->first();
$info['p_position'] = $position + 1;
}
catch( \UnderflowException $e ) { }
catch( UnderflowException $e ) { }
}
/* Base Price */
array_walk( $info['p_base_price'], function( &$value, $currency )
{
$price = new \IPS\nexus\Money( $value, $currency );
$price = new Money( $value, $currency );
$value = [ 'amount' => $price->amount, 'currency' => $currency ];
});
$basePrice = $info['p_base_price'];
@@ -1061,7 +1086,7 @@ class _Nexus extends \IPS\convert\Library
/* Renewal costs & terms */
$renewals = array();
if( isset( $info['p_renew_options'] ) AND \count( $info['p_renew_options'] ) )
if( isset( $info['p_renew_options'] ) AND count( $info['p_renew_options'] ) )
{
foreach ( $info['p_renew_options'] as $currency => $options )
{
@@ -1074,7 +1099,7 @@ class _Nexus extends \IPS\convert\Library
foreach ( $options['cost'] as $currency => $cost )
{
$price = new \IPS\nexus\Money( $cost, $currency );
$price = new Money( $cost, $currency );
$newOptions['cost'][ $currency ] = [ 'amount' => $price->amount, 'currency' => $currency ];
}
@@ -1092,7 +1117,7 @@ class _Nexus extends \IPS\convert\Library
$package = array(
'p_name' => $name,
'p_seo_name' => \IPS\Http\Url::seoTitle( $name ),
'p_seo_name' => url::seoTitle( $name ),
'p_group' => 0,
'p_stock' => -1,
'p_reg' => 0,
@@ -1141,7 +1166,7 @@ class _Nexus extends \IPS\convert\Library
);
/* Save Package Data */
$insertedId = \IPS\Db::i()->insert( 'nexus_packages', $this->_getValues( $package, $info ) );
$insertedId = Db::i()->insert( 'nexus_packages', $this->_getValues( $package, $info ) );
$originalId = $info['p_id'];
unset( $info['p_id'] );
@@ -1153,7 +1178,7 @@ class _Nexus extends \IPS\convert\Library
$default = 0;
foreach( $productImages as $image )
{
if ( ( isset( $image['data'] ) AND \is_null( $image['data'] ) ) AND !\is_null( $filePath ) )
if ( ( isset( $image['data'] ) AND is_null( $image['data'] ) ) AND !is_null( $filePath ) )
{
$filedata = @file_get_contents( rtrim( $filePath, '/' ) . '/' . $image['filename'] );
unset( $filepath );
@@ -1163,18 +1188,18 @@ class _Nexus extends \IPS\convert\Library
{
try
{
$file = \IPS\File::create( 'nexus_Products', $image['filename'], $filedata );
$file = File::create( 'nexus_Products', $image['filename'], $filedata );
$images[] = [ 'image_product' => $insertedId, 'image_location' => (string) $file, 'image_primary' => ( $default ? 0 : 1 ) ];
$default++;
}
catch( \Exception $e ) {}
catch( Exception $e ) {}
}
}
/* Insert Images */
if( \is_array( $images ) AND \count( $images ) )
if( is_array( $images ) AND count( $images ) )
{
\IPS\Db::i()->insert( 'nexus_package_images', $images );
Db::i()->insert( 'nexus_package_images', $images );
}
}
@@ -1197,7 +1222,7 @@ class _Nexus extends \IPS\convert\Library
);
/* Save Product Data */
\IPS\Db::i()->insert( 'nexus_packages_products', $this->_getValues( $product, $info ) );
Db::i()->insert( 'nexus_packages_products', $this->_getValues( $product, $info ) );
/* Add Link */
$this->software->app->addLink( $insertedId, $originalId, 'nexus_packages_products' );
@@ -1211,26 +1236,26 @@ class _Nexus extends \IPS\convert\Library
$this->convertNexusCurrency( [ 'code' => $currency ] );
/* Check the table */
if ( !\IPS\Db::i()->checkForColumn( 'nexus_package_base_prices', $currency ) )
if ( !Db::i()->checkForColumn( 'nexus_package_base_prices', $currency ) )
{
\IPS\Db::i()->addColumn( 'nexus_package_base_prices', array(
Db::i()->addColumn( 'nexus_package_base_prices', array(
'name' => $currency,
'type' => 'FLOAT'
) );
}
$insert[ $currency ] = (string) $amount['amount'];
}
\IPS\Db::i()->insert( 'nexus_package_base_prices', $insert );
Db::i()->insert( 'nexus_package_base_prices', $insert );
/* Custom lang strings */
\IPS\Lang::saveCustom( 'nexus', "nexus_package_{$insertedId}", $name );
\IPS\Lang::saveCustom( 'nexus', "nexus_package_{$insertedId}_desc", $description );
Lang::saveCustom( 'nexus', "nexus_package_{$insertedId}", $name );
Lang::saveCustom( 'nexus', "nexus_package_{$insertedId}_desc", $description );
/* Add Link */
$this->software->app->addLink( $insertedId, $originalId, 'nexus_packages' );
/* Update associations */
\IPS\Db::i()->update( 'nexus_packages', array( 'p_associable' => $insertedId ), array( 'p_conv_associable=?', $originalId ) );
Db::i()->update( 'nexus_packages', array( 'p_associable' => $insertedId ), array( 'p_conv_associable=?', $originalId ) );
return $insertedId;
}
@@ -1414,26 +1439,26 @@ class _Nexus extends \IPS\convert\Library
/* !Required: ID */
if ( !isset( $info['i_id'] ) )
{
$this->software->app->log( 'nexus_invoices_missing_id', __METHOD__, \IPS\convert\App::LOG_WARNING );
$this->software->app->log( 'nexus_invoices_missing_id', __METHOD__, App::LOG_WARNING );
return FALSE;
}
/* !Required: Currency */
if ( !isset( $currency ) OR !$currency = $this->convertNexusCurrency( [ 'code' => $currency ] ) )
{
$this->software->app->log( 'nexus_invoice_currency_invalid', __METHOD__, \IPS\convert\App::LOG_WARNING );
$this->software->app->log( 'nexus_invoice_currency_invalid', __METHOD__, App::LOG_WARNING );
return FALSE;
}
/* !Required: Items */
if ( !isset( $info['i_items'] ) OR !\is_array( $info['i_items'] ) )
if ( !isset( $info['i_items'] ) OR !is_array( $info['i_items'] ) )
{
$this->software->app->log( 'nexus_invoices_missing_items', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['i_id'] );
$this->software->app->log( 'nexus_invoices_missing_items', __METHOD__, App::LOG_WARNING, $info['i_id'] );
return FALSE;
}
/* Default Currency */
$price = new \IPS\nexus\Money( $info['i_total'], $currency );
$price = new Money( $info['i_total'], $currency );
$info['i_total'] = $price->amount;
/* ITEMS */
@@ -1446,12 +1471,12 @@ class _Nexus extends \IPS\convert\Library
unset( $item['item_type'] );
$newItems[] = $item;
}
catch( \OutOfRangeException $e ) {}
catch( OutOfRangeException $e ) {}
}
if( !\count( $newItems ) )
if( !count( $newItems ) )
{
$this->software->app->log( 'nexus_invoices_missing_mapped_items', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['i_id'] );
$this->software->app->log( 'nexus_invoices_missing_mapped_items', __METHOD__, App::LOG_WARNING, $info['i_id'] );
return FALSE;
}
@@ -1462,7 +1487,7 @@ class _Nexus extends \IPS\convert\Library
{
$info['i_member'] = $this->software->app->getLink( $info['i_member'], 'core_members', TRUE );
}
catch( \Exception $e )
catch( Exception $e )
{
unset( $info['i_member'] );
}
@@ -1474,7 +1499,7 @@ class _Nexus extends \IPS\convert\Library
/* Invoice */
$invoice = array(
'i_status' => \IPS\nexus\Invoice::STATUS_PENDING,
'i_status' => Invoice::STATUS_PENDING,
'i_title' => 'Converted Invoice '. $info['i_id'],
'i_member' => 0,
'i_items' => '[]',
@@ -1495,7 +1520,7 @@ class _Nexus extends \IPS\convert\Library
);
/* Save Invoice Data */
$insertedId = \IPS\Db::i()->insert( 'nexus_invoices', $this->_getValues( $invoice, $info ) );
$insertedId = Db::i()->insert( 'nexus_invoices', $this->_getValues( $invoice, $info ) );
/* Add Link */
$this->software->app->addLink( $insertedId, $info['i_id'], 'nexus_invoices' );
@@ -1515,35 +1540,35 @@ class _Nexus extends \IPS\convert\Library
/* !Required: ID */
if ( !isset( $info['t_id'] ) )
{
$this->software->app->log( 'nexus_transactions_missing_id', __METHOD__, \IPS\convert\App::LOG_WARNING );
$this->software->app->log( 'nexus_transactions_missing_id', __METHOD__, App::LOG_WARNING );
return FALSE;
}
/* !Required: MemberID */
if ( !isset( $info['t_member'] ) )
{
$this->software->app->log( 'nexus_transactions_missing_member_id', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['t_id'] );
$this->software->app->log( 'nexus_transactions_missing_member_id', __METHOD__, App::LOG_WARNING, $info['t_id'] );
return FALSE;
}
/* !Required: InvoiceID */
if ( !isset( $info['t_invoice'] ) )
{
$this->software->app->log( 'nexus_transactions_missing_invoice_id', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['t_id'] );
$this->software->app->log( 'nexus_transactions_missing_invoice_id', __METHOD__, App::LOG_WARNING, $info['t_id'] );
return FALSE;
}
/* !Required: Amount */
if ( !isset( $info['t_amount'] ) )
{
$this->software->app->log( 'nexus_transactions_missing_amount', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['t_id'] );
$this->software->app->log( 'nexus_transactions_missing_amount', __METHOD__, App::LOG_WARNING, $info['t_id'] );
return FALSE;
}
/* !Required: Currency */
if ( !isset( $currency ) OR !$currency = $this->convertNexusCurrency( [ 'code' => $currency ] ) )
{
$this->software->app->log( 'nexus_transaction_currency_invalid', __METHOD__, \IPS\convert\App::LOG_WARNING );
$this->software->app->log( 'nexus_transaction_currency_invalid', __METHOD__, App::LOG_WARNING );
return FALSE;
}
@@ -1552,9 +1577,9 @@ class _Nexus extends \IPS\convert\Library
{
$info['t_invoice'] = $this->software->app->getLink( $info['t_invoice'], 'nexus_invoices' );
}
catch( \OutOfRangeException $ex )
catch( OutOfRangeException $ex )
{
$this->software->app->log( 'nexus_transactions_missing_invoice', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['t_invoice'] );
$this->software->app->log( 'nexus_transactions_missing_invoice', __METHOD__, App::LOG_WARNING, $info['t_invoice'] );
return FALSE;
}
@@ -1562,9 +1587,9 @@ class _Nexus extends \IPS\convert\Library
{
$info['t_member'] = $this->software->app->getLink( $info['t_member'], 'core_members', TRUE );
}
catch( \OutOfRangeException $ex)
catch( OutOfRangeException $ex)
{
$this->software->app->log( 'nexus_transactions_missing_member', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['t_id'] );
$this->software->app->log( 'nexus_transactions_missing_member', __METHOD__, App::LOG_WARNING, $info['t_id'] );
return FALSE;
}
@@ -1575,21 +1600,21 @@ class _Nexus extends \IPS\convert\Library
{
$info['t_method'] = $this->software->app->getLink( $info['t_method'], 'nexus_payment_methods' );
}
catch ( \OutOfRangeException $ex )
catch ( OutOfRangeException $ex )
{
$info['t_method'] = 0;
}
}
/* Default Currency */
$price = new \IPS\nexus\Money( $info['t_amount'], $currency );
$price = new Money( $info['t_amount'], $currency );
$info['t_amount'] = $price->amount;
$transaction = array(
't_member' => 0,
't_invoice' => 0,
't_method' => 0,
't_status' => \IPS\nexus\Transaction::STATUS_PENDING,
't_status' => Transaction::STATUS_PENDING,
't_amount' => 0,
't_date' => time(),
't_extra' => '[]',
@@ -1605,7 +1630,7 @@ class _Nexus extends \IPS\convert\Library
);
/* Save Transaction Data */
$insertedId = \IPS\Db::i()->insert( 'nexus_transactions', $this->_getValues( $transaction, $info ) );
$insertedId = Db::i()->insert( 'nexus_transactions', $this->_getValues( $transaction, $info ) );
/* Add Link */
$this->software->app->addLink( $insertedId, $info['t_id'], 'nexus_transactions' );
@@ -1625,28 +1650,28 @@ class _Nexus extends \IPS\convert\Library
/* !Required: ID */
if ( !isset( $info['ps_id'] ) )
{
$this->software->app->log( 'nexus_purchases_missing_id', __METHOD__, \IPS\convert\App::LOG_WARNING );
$this->software->app->log( 'nexus_purchases_missing_id', __METHOD__, App::LOG_WARNING );
return FALSE;
}
/* !Required: MemberID */
if ( !isset( $info['ps_member'] ) )
{
$this->software->app->log( 'nexus_purchases_missing_member_id', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['ps_id'] );
$this->software->app->log( 'nexus_purchases_missing_member_id', __METHOD__, App::LOG_WARNING, $info['ps_id'] );
return FALSE;
}
/* !Required: InvoiceID */
if ( !isset( $info['ps_original_invoice'] ) )
{
$this->software->app->log( 'nexus_purchases_missing_invoice_id', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['ps_id'] );
$this->software->app->log( 'nexus_purchases_missing_invoice_id', __METHOD__, App::LOG_WARNING, $info['ps_id'] );
return FALSE;
}
/* !Required: Currency */
if ( !isset( $currency ) OR !$currency = $this->convertNexusCurrency( [ 'code' => $currency ] ) )
{
$this->software->app->log( 'nexus_purchase_currency_invalid', __METHOD__, \IPS\convert\App::LOG_WARNING );
$this->software->app->log( 'nexus_purchase_currency_invalid', __METHOD__, App::LOG_WARNING );
return FALSE;
}
@@ -1655,9 +1680,9 @@ class _Nexus extends \IPS\convert\Library
{
$info['ps_original_invoice'] = $this->software->app->getLink( $info['ps_original_invoice'], 'nexus_invoices' );
}
catch( \OutOfRangeException $ex)
catch( OutOfRangeException $ex)
{
$this->software->app->log( 'nexus_purchases_missing_invoice', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['ps_id'] );
$this->software->app->log( 'nexus_purchases_missing_invoice', __METHOD__, App::LOG_WARNING, $info['ps_id'] );
return FALSE;
}
@@ -1667,9 +1692,9 @@ class _Nexus extends \IPS\convert\Library
{
$info['ps_member'] = $this->software->app->getLink( $info['ps_member'], 'core_members', TRUE );
}
catch( \OutOfRangeException $ex)
catch( OutOfRangeException $ex)
{
$this->software->app->log( 'nexus_purchases_missing_member', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['ps_id'] );
$this->software->app->log( 'nexus_purchases_missing_member', __METHOD__, App::LOG_WARNING, $info['ps_id'] );
return FALSE;
}
@@ -1686,7 +1711,7 @@ class _Nexus extends \IPS\convert\Library
{
$info['ps_parent'] = $this->software->app->getLink( $info['ps_parent'], 'nexus_purchases' );
}
catch( \OutOfRangeException $ex )
catch( OutOfRangeException $ex )
{
$info['ps_conv_parent'] = $info['ps_parent'];
unset( $info['ps_parent'] );
@@ -1705,7 +1730,7 @@ class _Nexus extends \IPS\convert\Library
}
/* Old Secondary User Groups */
if( isset( $info['ps_extra']['nexus']['old_secondary_groups'] ) AND \is_array( $info['ps_extra']['nexus']['old_secondary_groups'] ) )
if( isset( $info['ps_extra']['nexus']['old_secondary_groups'] ) AND is_array( $info['ps_extra']['nexus']['old_secondary_groups'] ) )
{
$newSecondaryGroups = [];
@@ -1715,7 +1740,7 @@ class _Nexus extends \IPS\convert\Library
{
$newSecondaryGroups[] = $this->software->app->getLink( $group, 'core_groups', TRUE );
}
catch( \OutOfRangeException $ex ) { }
catch( OutOfRangeException $ex ) { }
}, $newSecondaryGroups );
$info['ps_extra']['nexus']['old_secondary_groups'] = $newSecondaryGroups;
@@ -1726,7 +1751,7 @@ class _Nexus extends \IPS\convert\Library
/* Default Currency */
if( isset( $info['ps_renewal_price'] ) )
{
$price = new \IPS\nexus\Money( $info['ps_renewal_price'], $currency );
$price = new Money( $info['ps_renewal_price'], $currency );
$info['ps_renewal_price'] = $price->amount;
}
@@ -1764,13 +1789,13 @@ class _Nexus extends \IPS\convert\Library
);
/* Save Purchase Data */
$insertedId = \IPS\Db::i()->insert( 'nexus_purchases', $this->_getValues( $purchase, $info ) );
$insertedId = Db::i()->insert( 'nexus_purchases', $this->_getValues( $purchase, $info ) );
/* Add Link */
$this->software->app->addLink( $insertedId, $info['ps_id'], 'nexus_purchases' );
/* Update associations */
\IPS\Db::i()->update( 'nexus_purchases', array( 'ps_parent' => $insertedId ), array( 'ps_conv_parent=?', $info['ps_id'] ) );
Db::i()->update( 'nexus_purchases', array( 'ps_parent' => $insertedId ), array( 'ps_conv_parent=?', $info['ps_id'] ) );
return $insertedId;
}
@@ -1803,7 +1828,7 @@ class _Nexus extends \IPS\convert\Library
*/
protected function _isPaymentMethodSupported( $method )
{
$availableGateways = \IPS\nexus\Gateway::gateways();
$availableGateways = Gateway::gateways();
$methodKey = array_search( $method, array_keys( array_change_key_case( $availableGateways, CASE_LOWER ) ) );
if( $methodKey !== FALSE )