Version 4.7.13

This commit is contained in:
Neo committed 2025-12-19 16:14:56 -08:00
1 parent fd22d99e69
commit 7124a02564
954 files changed
+29277 -59308

No files matched your search

+208 -4
View File
@@ -205,15 +205,37 @@ class _Nexus extends \IPS\convert\Library
'link_type' => 'nexus_coupons'
);
break;
case 'convertNexusSubscriptionPackages':
$return[ $k ] = [
'step_title' => 'convert_nexus_subscription_packages',
'step_method' => 'convertNexusSubscriptionPackages',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_member_subscription_packages' ),
'source_rows' => [ 'table' => $v['table'], 'where' => $v['where'] ],
'per_cycle' => 200,
'dependencies' => [],
'link_type' => 'nexus_subscription_package'
];
break;
case 'convertNexusInvoices':
$dependencies = array();
foreach( array( 'convertNexusCustomers', 'convertNexusPackages', 'convertNexusSubscriptionPackages' ) as $dependency )
{
$canConvert = $this->getConvertableItems();
if ( isset( $canConvert[ $dependency ] ) )
{
$dependencies[] = $dependency;
}
}
$return[ $k ] = array(
'step_title' => 'convert_nexus_invoices',
'step_method' => 'convertNexusInvoices',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_invoices' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers', 'convertNexusPackages' ),
'dependencies' => $dependencies,
'link_type' => 'nexus_invoices',
);
break;
@@ -242,13 +264,23 @@ class _Nexus extends \IPS\convert\Library
break;
case 'convertNexusPurchases':
$dependencies = array();
foreach( array( 'convertNexusCustomers', 'convertNexusPackages', 'convertNexusInvoices', 'convertNexusSubscriptionPackages' ) as $dependency )
{
$canConvert = $this->getConvertableItems();
if ( isset( $canConvert[ $dependency ] ) )
{
$dependencies[] = $dependency;
}
}
$return[ $k ] = array(
'step_title' => 'convert_nexus_purchases',
'step_method' => 'convertNexusPurchases',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers', 'convertNexusPackages', 'convertNexusInvoices' ),
'dependencies' => $dependencies,
'link_type' => 'nexus_purchases'
);
break;
@@ -433,6 +465,10 @@ class _Nexus extends \IPS\convert\Library
);
break;
case 'convertNexusSubscriptionPackages':
$return['convertNexusSubscriptionPackages'] = [ 'nexus_member_subscription_packages' => NULL ];
break;
case 'convertNexusPaymentMethods':
$return['convertNexusPaymentMethods'] = array( 'nexus_paymethods' => NULL );
break;
@@ -1199,6 +1235,173 @@ class _Nexus extends \IPS\convert\Library
return $insertedId;
}
/**
* Convert a subscription package
*
* @param array $info Info
* @param string|NULL $filePath Path to images
* @return int|bool The ID of the newly inserted package, or FALSE on failure
*/
public function convertNexusSubscriptionPackage( $info, $filePath=NULL )
{
/* !Required: ID */
if ( !isset( $info['sp_id'] ) )
{
$this->software->app->log( 'nexus_package_missing_id', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
if ( isset( $info['sp_name'] ) )
{
$name = $info['sp_name'];
unset( $info['sp_name'] );
}
else
{
$name = "Untitled Subscription {$info['sp_id']}";
}
if ( isset( $info['sp_description'] ) )
{
$description = $info['sp_description'];
unset( $info['sp_description'] );
}
else
{
$description = '';
}
/* !Required: Price */
if( !isset( $info['sp_price'] ) )
{
$this->software->app->log( 'nexus_subscription_missing_price', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['sp_id'] );
return FALSE;
}
/* Primary User Group */
if( isset( $info['sp_primary_group'] ) )
{
$info['sp_primary_group'] = $this->software->app->getLink( $info['sp_primary_group'], 'core_groups', TRUE );
}
/* Secondary User Groups */
if( isset( $info['sp_secondary_group'] ) )
{
$e = explode( ',', $info['sp_secondary_group'] );
$newSecondaryGroups = [];
array_walk( $info['sp_secondary_group'], function( $group, $key, &$newSecondaryGroups )
{
try
{
$newSecondaryGroups[] = $this->software->app->getLink( $group, 'core_groups', TRUE );
}
catch( \OutOfRangeException $ex ) { }
}, $newSecondaryGroups );
}
if ( !isset( $info['sp_position'] ) )
{
try
{
$position = \IPS\Db::i()->select( 'MAX(p_position)', 'nexus_subscription_packages' )->first();
$info['sp_position'] = $position + 1;
}
catch( \UnderflowException $e ) { }
}
/* Base Price */
if( isset( $info['sp_price'] ) AND \count( $info['sp_price'] ) )
{
$newOptions = array(
'cost' => [],
'term' => $info['sp_price']['term'],
'unit' => $info['sp_price']['unit'],
'add' => isset( $info['sp_price']['add'] ) ? $info['sp_price']['add'] : false
);
foreach ( $info['sp_price']['cost'] as $currency => $cost )
{
$price = new \IPS\nexus\Money( $cost, $currency );
$newOptions['cost'][ $currency ] = [ 'amount' => $price->amount, 'currency' => $currency ];
}
}
$basePrice = $newOptions;
unset( $info['sp_price'] );
/* Renewal costs & terms */
if( isset( $info['sp_renew_options'] ) AND \count( $info['sp_renew_options'] ) )
{
$newOptions = array(
'cost' => [],
'term' => $info['sp_renew_options']['term'],
'unit' => $info['sp_renew_options']['unit'],
'add' => isset( $info['sp_renew_options']['add'] ) ? $info['sp_renew_options']['add'] : false
);
foreach ( $info['sp_renew_options']['cost'] as $currency => $cost )
{
$price = new \IPS\nexus\Money( $cost, $currency );
$newOptions['cost'][ $currency ] = [ 'amount' => $price->amount, 'currency' => $currency ];
}
$info['sp_renew_options'] = json_encode( $newOptions );
}
$image = isset( $info['sp_image'] ) ? $info['sp_image'] : NULL;
unset( $info['sp_image'] );
$package = array(
'sp_reg_show' => 0,
'sp_featured' => 0,
'sp_price' => json_encode( $basePrice ),
'sp_tax' => 0,
'sp_primary_group' => 0,
'sp_secondary_group' => '',
'sp_return_primary' => 1,
'sp_position' => 0,
'sp_image' => NULL,
'sp_gateways' => '*',
'sp_renew_options' => '',
'sp_count_active' => 0,
'sp_count_inactive' => 0
);
/* Images */
if( $image )
{
if ( ( isset( $image['data'] ) AND \is_null( $image['data'] ) ) AND !\is_null( $filePath ) )
{
$filedata = @file_get_contents( rtrim( $filePath, '/' ) . '/' . $image['filename'] );
unset( $filepath );
}
if ( $filedata )
{
try
{
$info['sp_image'] = (string) \IPS\File::create( 'nexus_Products', $image['filename'], $filedata );
}
catch( \Exception $e ) {}
}
}
/* Save Package Data */
$insertedId = \IPS\Db::i()->insert( 'nexus_member_subscription_packages', $this->_getValues( $package, $info ) );
$originalId = $info['sp_id'];
unset( $info['sp_id'] );
/* Custom lang strings */
\IPS\Lang::saveCustom( 'nexus', "nexus_subs_{$insertedId}", $name );
\IPS\Lang::saveCustom( 'nexus', "nexus_subs_{$insertedId}_desc", $description );
/* Add Link */
$this->software->app->addLink( $insertedId, $originalId, 'nexus_members_subs_pkg' );
return $insertedId;
}
/**
* Convert an invoice
*
@@ -1239,7 +1442,8 @@ class _Nexus extends \IPS\convert\Library
{
try
{
$item['itemID'] = $this->software->app->getLink( $item['itemID'], 'nexus_packages' );
$item['itemID'] = $this->software->app->getLink( $item['itemID'], $item['item_type'] ?? 'nexus_packages' );
unset( $item['item_type'] );
$newItems[] = $item;
}
catch( \OutOfRangeException $e ) {}
@@ -1457,7 +1661,7 @@ class _Nexus extends \IPS\convert\Library
return FALSE;
}
$info['ps_item_id'] = $this->software->app->getLink( $info['ps_item_id'], 'nexus_packages' );
$info['ps_item_id'] = $this->software->app->getLink( $info['ps_item_id'], $info['ps_link_type'] ?? 'nexus_packages' );
try
{