Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+297 -123
View File
@@ -5,20 +5,21 @@
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @since 21 Jan 2015
*/
namespace IPS\convert\Library;
/* 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;
}
/**
* Invision Blog Converter
* @note We must extend the Core Library here so we can access methods like convertAttachment, convertFollow, etc
*/
class _Blog extends Core
@@ -37,19 +38,32 @@ class _Blog extends Core
public function menuRows( $rowCounts=FALSE )
{
$return = array();
$extraRows = $this->software->extraMenuRows();
foreach( $this->getConvertableItems() as $k => $v )
{
switch( $k )
{
case 'convertBlogCategories':
$return[ $k ] = array(
'step_title' => 'convert_blog_categories',
'step_method' => 'convertBlogCategories',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'blog_categories' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'blog_categories',
);
break;
case 'convertBlogs':
$return[ $k ] = array(
'step_title' => 'convert_blogs',
'step_method' => 'convertBlogs',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'blog_blogs' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'dependencies' => array(),
'per_cycle' => 200,
'dependencies' => array( 'convertBlogCategories' ),
'link_type' => 'blog_blogs',
);
break;
@@ -60,11 +74,23 @@ class _Blog extends Core
'step_method' => 'convertBlogEntries',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'blog_entries' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1500,
'dependencies' => array( 'convertBlogs' ),
'per_cycle' => 200,
'dependencies' => array( 'convertBlogs', 'convertBlogEntryCategories' ),
'link_type' => 'blog_entries',
);
break;
case 'convertBlogEntryCategories':
$return[ $k ] = array(
'step_title' => 'convert_blog_entry_categories',
'step_method' => 'convertBlogEntryCategories',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'blog_entry_categories' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'blog_entry_categories',
);
break;
case 'convertBlogComments':
$return[ $k ] = array(
@@ -72,7 +98,7 @@ class _Blog extends Core
'step_method' => 'convertBlogComments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'blog_comments' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1500,
'per_cycle' => 200,
'dependencies' => array( 'convertBlogEntries' ),
'link_type' => 'bog_comments',
);
@@ -84,7 +110,7 @@ class _Blog extends Core
'step_method' => 'convertBlogRssImport',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'blog_rss_import' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertBlogs' ),
'link_type' => 'blog_rss_import',
);
@@ -96,7 +122,7 @@ class _Blog extends Core
'step_method' => 'convertClubBlogs',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'blog_blogs', array( "blog_club_id IS NOT NULL" ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertClubs' ),
'link_type' => 'core_club_blogs'
);
@@ -108,7 +134,7 @@ class _Blog extends Core
'step_method' => 'convertClubBlogEntries',
'ips_rows' => \IPS\Db::i()->select( 'SUM(blog_entries)', 'blog_blogs', array( "blog_club_id IS NOT NULL" ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'per_cycle' => 200,
'dependencies' => array( 'convertClubBlogs' ),
'link_type' => 'core_club_blogs_entries',
'requires_rebuild' => TRUE
@@ -121,7 +147,7 @@ class _Blog extends Core
'step_method' => 'convertClubBlogComments',
'ips_rows' => \IPS\Db::i()->select( 'SUM(blog_comments)', 'blog_blogs', array( "blog_club_id IS NOT NULL" ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'per_cycle' => 200,
'dependencies' => array( 'convertClubBlogEntries' ),
'link_type' => 'core_club_blogs_comments',
'requires_rebuild' => TRUE
@@ -134,15 +160,22 @@ class _Blog extends Core
'step_method' => 'convertAttachments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'core_attachments_map', array( 'location_key=? AND id1<>? AND id2 IS NULL', 'blog_Entries', 0 ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 250,
'per_cycle' => 10,
'dependencies' => array( 'convertBlogEntries', 'convertBlogComments' ),
'link_type' => 'core_attachments',
);
break;
}
}
$return = $this->software->extraMenuRows( $return );
/* Append any extra steps immediately to retain ordering */
if( isset( $v['extra_steps'] ) )
{
foreach( $v['extra_steps'] as $extra )
{
$return[ $extra ] = $extraRows[ $extra ];
}
}
}
/* Run the queries if we want row counts */
if( $rowCounts )
@@ -156,12 +189,13 @@ class _Blog extends Core
/**
* Returns an array of tables that need to be truncated when Empty Local Data is used
*
* @param string $method Method we are truncating
* @return array
*/
protected function truncate( $method )
{
$return = array();
$classname = get_class( $this->software );
$classname = \get_class( $this->software );
if( $classname::canConvert() === NULL )
{
@@ -176,10 +210,18 @@ class _Blog extends Core
case 'convertBlogs':
$return['convertBlogs'] = array( 'blog_blogs' => NULL, 'core_clubs_node_map' => array( "node_class=?", "IPS\\blog\\Blog" ) );
break;
case 'convertBlogCategories':
$return['convertBlogCategories'] = array( 'blog_categories' => NULL );
break;
case 'convertBlogEntries':
$return['convertBlogEntries'] = array( 'blog_entries' => NULL );
break;
case 'convertBlogEntryCategories':
$return['convertBlogEntryCategories'] = array( 'blog_entry_categories' => NULL );
break;
case 'convertBlogComments':
$return['convertBlogComments'] = array( 'blog_comments' => NULL );
@@ -292,12 +334,12 @@ class _Blog extends Core
if ( isset( $info['blog_settings'] ) )
{
if ( !is_array( $info['blog_settings'] ) )
if ( !\is_array( $info['blog_settings'] ) )
{
$info['blog_settings'] = json_decode( $info['blog_settings'], TRUE );
}
if ( !is_null( $info['blog_settings'] ) )
if ( !\is_null( $info['blog_settings'] ) )
{
$newSettings = array();
@@ -369,13 +411,13 @@ class _Blog extends Core
if ( isset( $info['blog_groupblog_ids'] ) )
{
if ( !is_array( $info['blog_groupblog_ids'] ) )
if ( !\is_array( $info['blog_groupblog_ids'] ) )
{
$info['blog_groupblog_ids'] = explode( ',', $info['blog_groupblog_ids'] );
}
$newGroups = array();
if ( count( $info['blog_groupblog_ids'] ) )
if ( \count( $info['blog_groupblog_ids'] ) )
{
foreach( $info['blog_groupblog_ids'] AS $group )
{
@@ -390,7 +432,7 @@ class _Blog extends Core
}
}
if ( count( $newGroups ) )
if ( \count( $newGroups ) )
{
$info['blog_groupblog_ids'] = implode( ',', $newGroups );
}
@@ -434,7 +476,7 @@ class _Blog extends Core
/* Well update this later if we need too */
$info['blog_social_group'] = NULL;
if ( !is_null( $socialgroup ) AND is_array( $socialgroup ) )
if ( !\is_null( $socialgroup ) AND \is_array( $socialgroup ) )
{
$socialGroupId = \IPS\Db::i()->insert( 'core_sys_social_groups', array( 'owner_id' => $info['blog_member_id'] ) );
$members = array();
@@ -445,7 +487,7 @@ class _Blog extends Core
{
$members[] = array( 'group_id' => $socialGroupId, 'member_id' => $this->software->app->getLink( $member, 'core_members', TRUE ) );
}
catch( \OutOfRangeExceptin $e )
catch( \OutOfRangeException $e )
{
continue;
}
@@ -456,11 +498,11 @@ class _Blog extends Core
}
/* And now cover photo */
if ( isset( $info['blog_cover_photo'] ) AND ( !is_null( $filedata ) OR !is_null( $filepath ) ) )
if ( isset( $info['blog_cover_photo'] ) AND ( !\is_null( $filedata ) OR !\is_null( $filepath ) ) )
{
try
{
if ( is_null( $filedata ) AND !is_null( $filepath ) )
if ( \is_null( $filedata ) AND !\is_null( $filepath ) )
{
$filedata = file_get_contents( $filepath );
}
@@ -501,6 +543,22 @@ class _Blog extends Core
{
$info['blog_club_id'] = NULL;
}
if( !empty( $info['blog_category_id'] ) )
{
try
{
$info['blog_category_id'] = $this->software->app->getLink( $info['blog_category_id'], 'blog_categories' );
}
catch( \OutOfRangeException $e )
{
$info['blog_category_id'] = $this->_getOrphanedBlogCategory();
}
}
else
{
$info['blog_category_id'] = $this->_getOrphanedBlogCategory();
}
$id = $info['blog_id'];
unset( $info['blog_id'] );
@@ -525,6 +583,88 @@ class _Blog extends Core
return $inserted_id;
}
/**
* Convert a Blog Category
*
* @param array $info Array of blog information
* @return integer|boolean The ID of the inserted category, or FALSE on failure.
*/
public function convertBlogCategory( array $info )
{
if ( !isset( $info['category_id'] ) )
{
$this->software->app->log( 'blog_category_missing_ids', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
if ( !isset( $info['category_name'] ) )
{
$name = "Converted Category {$info['category_id']}";
$this->software->app->log( 'blog_category_missing_name', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['category_id'] );
}
else
{
$name = $info['category_name'];
unset( $info['category_name'] );
}
$info['category_seo_name'] = \IPS\Http\Url::seoTitle( $name );
if ( !array_key_exists( 'category_description', $info ) )
{
$desc = '';
}
else
{
/* Make sure the description isn't empty/null */
$desc = $info['category_description'] ?: '';
unset( $info['category_description'] );
}
if ( !isset( $info['category_position'] ) )
{
try
{
$position = \IPS\Db::i()->select( 'MAX(category_position)', 'blog_categories' )->first();
}
catch( \UnderflowException $e )
{
$position = 0;
}
$info['category_position'] = $position + 1;
}
if ( isset( $info['category_parent'] ) )
{
try
{
$info['category_parent'] = $this->software->app->getLink( $info['category_parent'], 'blog_categories' );
}
catch( \OutOfRangeException $e )
{
$info['category_conv_parent'] = $info['category_parent'];
}
}
else
{
$info['category_parent'] = 0;
}
$id = $info['category_id'];
unset( $info['category_id'] );
$insertedId = \IPS\Db::i()->insert( 'blog_categories', $info );
$this->software->app->addLink( $insertedId, $id, 'blog_categories' );
\IPS\Lang::saveCustom( 'blogs', "blog_category_{$insertedId}", $name );
\IPS\Lang::saveCustom( 'blogs', "blog_category_{$insertedId}_desc", $desc );
\IPS\Db::i()->update( 'blog_categories', array( "category_parent" => $insertedId ), array( "category_conv_parent=?", $id ) );
return $insertedId;
}
/**
* Convert a blog entry
@@ -611,7 +751,7 @@ class _Blog extends Core
$info['entry_date'] = time();
}
if ( !isset( $info['entry_status'] ) OR !in_array( $info['entry_status'], array( 'published', 'draft' ) ) )
if ( !isset( $info['entry_status'] ) OR !\in_array( $info['entry_status'], array( 'published', 'draft' ) ) )
{
$info['entry_status'] = 'published';
}
@@ -664,6 +804,16 @@ class _Blog extends Core
{
$info['entry_edit_name'] = NULL;
}
if ( !isset( $info['entry_edit_reason'] ) )
{
$info['entry_edit_reason'] = '';
}
if ( !isset( $info['entry_append_edit'] ) )
{
$info['entry_append_edit'] = 0;
}
if ( isset( $info['entry_last_update'] ) )
{
@@ -693,7 +843,7 @@ class _Blog extends Core
$info['entry_gallery_album'] = NULL;
}
if ( isset( $info['entry_poll_state'] ) AND is_array( $info['entry_poll_state'] ) )
if ( isset( $info['entry_poll_state'] ) AND \is_array( $info['entry_poll_state'] ) )
{
if ( $poll = $this->convertPoll( $info['entry_poll_state']['poll_data'], $info['entry_poll_state']['vote_data'] ) )
{
@@ -728,11 +878,11 @@ class _Blog extends Core
$info['entry_ip_address'] = '127.0.0.1';
}
if ( isset( $info['entry_cover_photo'] ) AND ( !is_null( $filepath ) OR !is_null( $filedata ) ) )
if ( isset( $info['entry_cover_photo'] ) AND ( !\is_null( $filepath ) OR !\is_null( $filedata ) ) )
{
try
{
if ( is_null( $filedata ) AND !is_null( $filepath ) )
if ( \is_null( $filedata ) AND !\is_null( $filepath ) )
{
$filedata = file_get_contents( $filepath );
}
@@ -752,6 +902,22 @@ class _Blog extends Core
$info['entry_cover_photo'] = NULL;
$info['entry_cover_photo_offset'] = NULL;
}
if( !empty( $info['entry_category_id'] ) )
{
try
{
$info['entry_category_id'] = $this->software->app->getLink( $info['entry_category_id'], 'blog_entry_categories' );
}
catch( \OutOfRangeException $e )
{
$info['entry_category_id'] = NULL;
}
}
else
{
$info['entry_category_id'] = NULL;
}
$id = $info['entry_id'];
unset( $info['entry_id'] );
@@ -761,6 +927,80 @@ class _Blog extends Core
return $inserted_id;
}
/**
* Convert a Blog Entry Category
*
* @param array $info Array of blog information
* @return integer|boolean The ID of the inserted category, or FALSE on failure.
*/
public function convertBlogEntryCategory( array $info )
{
if ( !isset( $info['entry_category_id'] ) )
{
$this->software->app->log( 'blog_entry_category_missing_ids', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
if ( !isset( $info['entry_category_blog_id'] ) )
{
$this->software->app->log( 'blog_entry_category_blog_missing_ids', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
if ( isset( $info['entry_category_blog_id'] ) )
{
try
{
$info['entry_category_blog_id'] = $this->software->app->getLink( $info['entry_category_blog_id'], 'blog_blogs' );
}
catch( \OutOfRangeException $e )
{
$this->software->app->log( 'blog_entry_category_missing_blog_id', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['entry_category_id'] );
return FALSE;
}
}
else
{
$this->software->app->log( 'blog_entry_category_missing_blog_id', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['entry_category_id'] );
return FALSE;
}
if ( !isset( $info['entry_category_name'] ) )
{
$info['entry_category_name'] = "Converted Category {$info['entry_category_id']}";
$this->software->app->log( 'blog_entry_category_missing_name', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['entry_category_id'] );
}
$info['entry_category_seo_name'] = \IPS\Http\Url::seoTitle( $info['entry_category_name'] );
if ( !isset( $info['entry_category_position'] ) )
{
try
{
$position = \IPS\Db::i()->select( 'MAX(entry_category_position)', 'blog_entry_categories', array( 'entry_category_blog_id=?', $info['entry_category_blog_id'] ) )->first();
}
catch( \UnderflowException $e )
{
$position = 0;
}
$info['entry_category_position'] = $position + 1;
}
if ( !isset( $info['entry_category_count'] ) )
{
$info['entry_category_count'] = 0;
}
$id = $info['entry_category_id'];
unset( $info['entry_category_id'] );
$insertedId = \IPS\Db::i()->insert( 'blog_entry_categories', $info );
$this->software->app->addLink( $insertedId, $id, 'blog_entry_categories' );
return $insertedId;
}
/**
* Convert a blog comment
@@ -891,115 +1131,26 @@ class _Blog extends Core
*/
public function convertBlogRssImport( array $info )
{
if ( !isset( $info['rss_id'] ) )
{
$this->software->app->log( 'blog_rss_import_missing_ids', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
if ( isset( $info['rss_blog_id'] ) )
{
try
{
$info['rss_blog_id'] = $this->software->app->getLink( $info['rss_blog_id'], 'blog_blogs' );
}
catch( \OutOfRangeException $e )
{
$this->software->app->log( 'blog_rss_import_missing_blog', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['rss_id'] );
return FALSE;
}
}
else
{
$this->software->app->log( 'blog_rss_import_missing_blog', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['rss_id'] );
return FALSE;
}
if ( !isset( $info['rss_url'] ) OR filter_var( $info['rss_url'], FILTER_VALIDATE_URL ) === FALSE )
{
$this->software->app->log( 'blog_rss_import_missing_url', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['rss_id'] );
return FALSE;
}
if ( !isset( $info['rss_auth_user'] ) OR !isset( $info['rss_auth_pass'] ) )
{
$info['rss_auth_user'] = '';
$info['rss_auth_pass'] = '';
}
if ( isset( $info['rss_last_import'] ) )
{
if ( $info['rss_last_import'] instanceof \IPS\DateTime )
{
$info['rss_last_import'] = $info['rss_last_import']->getTimestamp();
}
}
else
{
$info['rss_last_import'] = time();
}
if ( isset( $info['rss_tags'] ) )
{
if ( is_array( $info['rss_tags'] ) )
{
$info['rss_tags'] = json_encode( $info['rss_tags'] );
}
}
else
{
$info['rss_tags'] = NULL;
}
if ( isset( $info['rss_member'] ) )
{
try
{
$info['rss_member'] = $this->software->app->getLink( $info['rss_member'], 'core_members', TRUE );
}
catch( \OutOfRangeException $e )
{
$info['rss_member'] = NULL;
}
}
else
{
$info['rss_member'] = NULL;
}
if ( is_null( $info['rss_member'] ) )
{
$blogOwner = \IPS\Db::i()->select( 'blog_member_id', 'blog_blogs', array( "blog_id=?", $info['rss_blog_id'] ) )->first();
$info['rss_member'] = $blogOwner;
}
if ( !isset( $info['rss_import_show_link'] ) )
{
$info['rss_import_show_link'] = "View the full article";
}
$id = $info['rss_id'];
unset( $info['rss_id'] );
$inserted_id = \IPS\Db::i()->insert( 'blog_rss_import', $info );
$this->software->app->addLinK( $inserted_id, $id, 'blog_rss_import' );
return $inserted_id;
$info['rss_import_class'] = 'IPS\\blogs\\Entry';
return parent::convertRssImport( $info, 'blog_blogs', 'blog_rss_import' );
}
/**
* Convert a blog entry attachment
*
* @param array $info Array of entry attachment information
* @param array $map Array of attachment map data
* @param string|NULL $filepath URL/Path to attachment or NULL to use raw file data
* @param string|NULL $filedata If $filepath is NULL, this should contain the raw contents of the attachment
* @param string|NULL $thumbnailpath Path to thumbnail, or NULL
* @return integer|boolean The ID of the inserted attachment, or FALSE on failure.
*/
public function convertAttachment( $info=array(), $map=array(), $filepath = NULL, $filedata = NULL, $thumbnailpath = NULL )
{
$map['id1_type'] = 'blog_entries';
$map['id1_from_parent'] = FALSE;
if ( !isset( $info['id2'] ) OR is_null( $info['id2'] ) )
if ( !isset( $info['id2'] ) OR \is_null( $info['id2'] ) )
{
$map['location_key'] = 'blog_Entries';
}
@@ -1060,4 +1211,27 @@ class _Blog extends Core
}
return $insertedId;
}
/**
* Get Parent ID for Orphaned Blogs
*
* @return integer The ID of the forum created for forums that do not have a parent forum.
*/
protected function _getOrphanedBlogCategory()
{
try
{
$id = $this->software->app->getLink( '__orphaned__', 'blog_categories' );
}
catch( \OutOfRangeException $e )
{
$id = $this->convertBlogCategory( array(
'category_id' => '__orphaned__',
'category_name' => "Converted Blogs",
'category_parent' => 0,
) );
}
return $id;
}
}
@@ -5,19 +5,23 @@
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @since 21 Jan 2015
*/
namespace IPS\convert\Library;
/* 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;
}
/**
* Invision Forums Converter
* @note Alias for Forums
*/
class _Board extends Forums
{
@@ -5,19 +5,23 @@
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @since 21 Jan 2015
*/
namespace IPS\convert\Library;
/* 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;
}
/**
* Invision Calendar Converter
* @note We must extend the Core Library here so we can access methods like convertAttachment, convertFollow, etc
*/
class _Calendar extends Core
{
/**
@@ -34,6 +38,7 @@ class _Calendar extends Core
public function menuRows( $rowCounts=FALSE )
{
$return = array();
$extraRows = $this->software->extraMenuRows();
foreach( $this->getConvertableItems() as $k => $v )
{
@@ -45,7 +50,7 @@ class _Calendar extends Core
'step_method' => 'convertCalendarCalendars',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'calendar_calendars' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'calendar_calendars',
);
@@ -57,7 +62,7 @@ class _Calendar extends Core
'step_method' => 'convertCalendarVenues',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'calendar_venues' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array( 'convertCalendarCalendars' ),
'link_type' => 'calendar_venues',
);
@@ -69,7 +74,7 @@ class _Calendar extends Core
'step_method' => 'convertCalendarEvents',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'calendar_events' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1500,
'per_cycle' => 200,
'dependencies' => array( 'convertCalendarCalendars' ),
'link_type' => 'calendar_events',
'requires_rebuild' => TRUE
@@ -82,7 +87,7 @@ class _Calendar extends Core
'step_method' => 'convertCalendarComments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'calendar_event_comments' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertCalendarEvents' ),
'link_type' => 'calendar_event_comments',
'requires_rebuild' => TRUE
@@ -95,7 +100,7 @@ class _Calendar extends Core
'step_method' => 'convertCalendarReviews',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'calendar_event_reviews' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertCalendarEvents' ),
'link_type' => 'calendar_event_reviews',
'requires_rebuild' => TRUE
@@ -108,7 +113,7 @@ class _Calendar extends Core
'step_method' => 'convertCalendarRsvps',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'calendar_event_rsvp' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertCalendarEvents' ),
'link_type' => 'calendar_event_rsvp',
);
@@ -120,7 +125,7 @@ class _Calendar extends Core
'step_method' => 'convertCalendarFeeds',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'calendar_import_feeds' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array( 'convertCalendarCalendars' ),
'link_type' => 'calendar_import_feeds',
);
@@ -132,7 +137,7 @@ class _Calendar extends Core
'step_method' => 'convertCalendarReminders',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'calendar_event_reminders' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array( 'convertCalendarEvents' ),
'link_type' => 'calendar_reminders',
);
@@ -144,15 +149,22 @@ class _Calendar extends Core
'step_method' => 'convertAttachments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'core_attachments_map', array( "location_key=?", 'calendar_Calendar' ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 10,
'dependencies' => array( 'convertCalendarEvents' ),
'link_type' => 'core_attachments',
);
break;
}
}
$return = $this->software->extraMenuRows( $return );
/* Append any extra steps immediately to retain ordering */
if( isset( $v['extra_steps'] ) )
{
foreach( $v['extra_steps'] as $extra )
{
$return[ $extra ] = $extraRows[ $extra ];
}
}
}
/* Run the queries if we want row counts */
if( $rowCounts )
@@ -166,12 +178,13 @@ class _Calendar extends Core
/**
* Returns an array of tables that need to be truncated when Empty Local Data is used
*
* @param string $method Method to truncate
* @return array
*/
protected function truncate( $method )
{
$return = array();
$classname = get_class( $this->software );
$classname = \get_class( $this->software );
if( $classname::canConvert() === NULL )
{
@@ -465,7 +478,7 @@ class _Calendar extends Core
if ( isset( $info['event_recurring'] ) )
{
/* If we have an array, pass off to ICSParser so we can build it */
if ( is_array( $info['event_recurring'] ) )
if ( \is_array( $info['event_recurring'] ) )
{
$info['event_recurring'] = \IPS\calendar\Icalendar\ICSParser::buildRrule( $info['event_recurring'] );
}
@@ -588,7 +601,7 @@ class _Calendar extends Core
if ( isset( $info['event_location'] ) )
{
if ( is_array( $info['event_location'] ) AND isset( $info['event_location']['lat'] ) AND isset( $info['event_location']['long'] ) )
if ( \is_array( $info['event_location'] ) AND isset( $info['event_location']['lat'] ) AND isset( $info['event_location']['long'] ) )
{
$info['event_location'] = (string) \IPS\GeoLocation::getFromLatLong( $info['event_location']['lat'], $info['event_location']['long'] );
}
@@ -623,11 +636,11 @@ class _Calendar extends Core
$info['event_album'] = NULL;
}
if ( isset( $info['event_cover_photo'] ) AND ( !is_null( $filepath ) OR !is_null( $filedata ) ) )
if ( isset( $info['event_cover_photo'] ) AND ( !\is_null( $filepath ) OR !\is_null( $filedata ) ) )
{
try
{
if ( is_null( $filedata ) AND !is_null( $filepath ) )
if ( \is_null( $filedata ) AND !\is_null( $filepath ) )
{
$filedata = file_get_contents( $filepath );
}
@@ -648,6 +661,33 @@ class _Calendar extends Core
{
$info['event_cover_photo'] = NULL;
}
if ( isset( $info['event_edit_time'] ) )
{
if ( $info['event_edit_time'] instanceof \IPS\DateTime )
{
$info['event_edit_time'] = $info['event_edit_time']->getTimestamp();
}
}
else
{
$info['event_edit_time'] = NULL;
}
if ( !isset( $info['event_edit_member_name'] ) )
{
$info['event_edit_member_name'] = NULL;
}
if ( !isset( $info['event_edit_reason'] ) )
{
$info['event_edit_reason'] = '';
}
if ( !isset( $info['event_append_edit'] ) )
{
$info['event_append_edit'] = 0;
}
$id = $info['event_id'];
unset( $info['event_id'] );
@@ -898,13 +938,13 @@ class _Calendar extends Core
if ( isset( $info['review_votes_data'] ) )
{
if ( !is_array( $info['review_votes_data'] ) )
if ( !\is_array( $info['review_votes_data'] ) )
{
$info['review_votes_data'] = json_decode( $info['review_votes_data'], TRUE );
}
$newVoters = array();
if ( !is_null( $info['review_votes_data'] ) AND count( $info['review_votes_data'] ) )
if ( !\is_null( $info['review_votes_data'] ) AND \count( $info['review_votes_data'] ) )
{
foreach( $info['review_votes_data'] as $member => $vote )
{
@@ -921,7 +961,7 @@ class _Calendar extends Core
}
}
if ( count( $newVoters ) )
if ( \count( $newVoters ) )
{
$info['review_votes_data'] = json_encode( $newVoters );
}
@@ -937,19 +977,19 @@ class _Calendar extends Core
if ( !isset( $info['review_votes'] ) )
{
if ( is_null( $info['review_votes_data'] ) )
if ( \is_null( $info['review_votes_data'] ) )
{
$info['review_votes'] = 0;
}
else
{
$info['review_votes'] = count( json_decode( $info['review_votes_data'], TRUE ) );
$info['review_votes'] = \count( json_decode( $info['review_votes_data'], TRUE ) );
}
}
if ( !isset( $info['review_votes_helpful'] ) )
{
if ( is_null( $info['review_votes_data'] ) )
if ( \is_null( $info['review_votes_data'] ) )
{
$info['review_votes_helpful'] = 0;
}
@@ -1044,7 +1084,7 @@ class _Calendar extends Core
$info['rsvp_date'] = time();
}
if ( !isset( $info['rsvp_response'] ) OR !in_array( $info['rsvp_response'], array( 0, 1, 2 ) ) )
if ( !isset( $info['rsvp_response'] ) OR !\in_array( $info['rsvp_response'], array( 0, 1, 2 ) ) )
{
$this->software->app->log( 'calendar_rsvp_invalid_response', __METHOD__, \IPS\convert\App::LOG_WARNING, ( $hasId ) ? $info['rsvp_id'] : NULL );
return FALSE;
@@ -1205,7 +1245,7 @@ class _Calendar extends Core
if ( isset( $info['venue_address'] ) )
{
if ( is_array( $info['venue_address'] ) AND isset( $info['venue_address']['lat'] ) AND isset( $info['venue_address']['long'] ) )
if ( \is_array( $info['venue_address'] ) AND isset( $info['venue_address']['lat'] ) AND isset( $info['venue_address']['long'] ) )
{
$info['venue_address'] = (string) \IPS\GeoLocation::getFromLatLong( $info['venue_address']['lat'], $info['venue_address']['long'] );
}
@@ -1323,6 +1363,7 @@ class _Calendar extends Core
* @param array $map Attachment Map Data
* @param string|NULL $filepath Path to the file, or NULL.
* @param string|NULL $filedata Binary data for the file, or NULL.
* @param string|NULL $thumbnailpath Path to thumbnail, or NULL.
* @return integer|boolean The ID of the newly inserted attachment, or FALSE on failure.
*/
public function convertAttachment( $info=array(), $map=array(), $filepath=NULL, $filedata=NULL, $thumbnailpath=NULL )
@@ -1338,7 +1379,7 @@ class _Calendar extends Core
$map['id3'] = NULL;
}
if ( is_null( $map['id3'] ) OR $map['id3'] != 'review' )
if ( \is_null( $map['id3'] ) OR $map['id3'] != 'review' )
{
$map['id2_type'] = 'calendar_event_comments';
}
+6 -2
View File
@@ -5,19 +5,23 @@
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @since 21 Jan 2015
*/
namespace IPS\convert\Library;
/* 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;
}
/**
* Invision Pages Converter
* @note Alias for Cms
*/
class _Ccs extends Cms
{
+129 -72
View File
@@ -5,20 +5,21 @@
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @since 21 Jan 2015
*/
namespace IPS\convert\Library;
/* 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;
}
/**
* Invision Pages Support
* @note We must extend the Core Library here so we can access methods like convertAttachment, convertFollow, etc
*/
class _Cms extends Core
@@ -47,6 +48,7 @@ class _Cms extends Core
public function menuRows( $rowCounts=FALSE )
{
$return = array();
$extraRows = $this->software->extraMenuRows();
foreach( $this->getConvertableItems() as $k => $v )
{
@@ -75,7 +77,7 @@ class _Cms extends Core
'step_method' => 'convertCmsContainers',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'cms_containers' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'cms_containers',
);
@@ -104,7 +106,7 @@ class _Cms extends Core
'step_method' => 'convertCmsDatabaseCategories',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'cms_database_categories' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array( 'convertCmsDatabases' ),
'link_type' => 'cms_database_categories',
);
@@ -122,7 +124,7 @@ class _Cms extends Core
$links[] = "cms_custom_database_{$database}";
}
$dependencies = array();
$dependencies = array( 'convertCmsDatabases' );
if ( array_key_exists( 'convertCmsDatabaseCategories', $this->getConvertableItems() ) )
{
$dependencies[] = 'convertCmsDatabaseCategories';
@@ -133,8 +135,8 @@ class _Cms extends Core
'step_method' => 'convertCmsDatabaseRecords',
'ips_rows' => $count,
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'dependencies' => array( 'convertCmsDatabases' ),
'per_cycle' => 200,
'dependencies' => $dependencies,
'link_type' => $links,
'requires_rebuild' => TRUE
);
@@ -146,7 +148,7 @@ class _Cms extends Core
'step_method' => 'convertCmsDatabaseComments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'cms_database_comments' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertCmsDatabaseRecords' ),
'link_type' => 'cms_database_comments',
'requires_rebuild' => TRUE
@@ -159,7 +161,7 @@ class _Cms extends Core
'step_method' => 'convertCmsDatabaseReviews',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'cms_database_reviews' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertCmsDatabaseRecords' ),
'link_type' => 'cms_database_reviews',
'requires_rebuild' => TRUE
@@ -172,7 +174,7 @@ class _Cms extends Core
'step_method' => 'convertCmsFolders',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'cms_folders' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'cms_folders',
);
@@ -190,7 +192,7 @@ class _Cms extends Core
'step_method' => 'convertCmsMedia',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'cms_media' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 10,
'dependencies' => $dependencies,
'link_type' => 'cms_media',
);
@@ -202,7 +204,7 @@ class _Cms extends Core
'step_method' => 'convertCmsMediaFolders',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'cms_media_folders' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'cms_media_folders',
);
@@ -227,6 +229,18 @@ class _Cms extends Core
break;
case 'convertAttachments':
$dependencies = array( 'convertCmsDatabaseRecords' );
if ( array_key_exists( 'convertCmsDatabaseComments', $this->getConvertableItems() ) )
{
$dependencies[] = 'convertCmsDatabaseComments';
}
if ( array_key_exists( 'convertCmsDatabaseReviews', $this->getConvertableItems() ) )
{
$dependencies[] = 'convertCmsDatabaseReviews';
}
$in = array();
foreach( \IPS\Db::i()->select( 'database_id', 'cms_databases' ) AS $database )
{
@@ -238,16 +252,22 @@ class _Cms extends Core
'step_method' => 'convertAttachments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'core_attachments_map', array( \IPS\Db::i()->in( 'id3', $in ) . " AND location_key=?", 'cms_Records' ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
#'dependencies' => array( 'convertCmsDatabaseRecords', 'convertCmsDatabaseComments', 'convertCmsDatabaseReviews' ),
'dependencies' => array( 'convertCmsDatabaseRecords' ), //TODO dear code reviewer... please review this part.. i had to remove it for my further work
'per_cycle' => 10,
'dependencies' => $dependencies,
'link_type' => 'core_attachments',
);
break;
}
}
$return = $this->software->extraMenuRows( $return );
/* Append any extra steps immediately to retain ordering */
if( isset( $v['extra_steps'] ) )
{
foreach( $v['extra_steps'] as $extra )
{
$return[ $extra ] = $extraRows[ $extra ];
}
}
}
/* Run the queries if we want row counts */
if( $rowCounts )
@@ -261,12 +281,13 @@ class _Cms extends Core
/**
* Returns an array of tables that need to be truncated when Empty Local Data is used
*
* @param string $method Method to truncate
* @return array
*/
protected function truncate( $method )
{
$return = array();
$classname = get_class( $this->software );
$classname = \get_class( $this->software );
foreach( $classname::canConvert() as $k => $v )
{
switch( $k )
@@ -284,7 +305,10 @@ class _Cms extends Core
break;
case 'convertCmsBlocks':
$return['convertCmsBlocks'] = array( 'cms_blocks' => NULL );
$return['convertCmsBlocks'] = array(
'cms_blocks' => NULL,
'core_permission_index' => array( 'app=? AND perm_type=?', 'cms', 'blocks' )
);
break;
case 'convertCmsDatabases':
@@ -420,7 +444,7 @@ class _Cms extends Core
$inserted_id = \IPS\Db::i()->insert( 'cms_folders', $info );
$this->software->app->addLink( $inserted_id, $id, 'cms_folders' );
\IPS\Db::i()->update( 'cms_folders', array( 'folder_parent_id' => $inserted_id ), array( "folder_conv_parent=? AND folder_conv_parent<>?", $id, 0 ) );
\IPS\Db::i()->update( 'cms_folders', array( 'folder_parent_id' => $inserted_id ), array( "folder_conv_parent=?", $id ) );
return $inserted_id;
}
@@ -466,7 +490,7 @@ class _Cms extends Core
if ( isset( $info['page_meta_keywords'] ) )
{
if ( is_array( $info['page_meta_keywords'] ) )
if ( \is_array( $info['page_meta_keywords'] ) )
{
$info['page_meta_keywords'] = implode( ',', $info['page_meta_keywords'] );
}
@@ -511,7 +535,7 @@ class _Cms extends Core
try
{
/* Check folder */
if ( intval( $info['page_folder_id'] ) == \IPS\cms\Pages\Folder::load( $info['page_seo_name'], 'folder_name' )->parent_id )
if ( \intval( $info['page_folder_id'] ) == \IPS\cms\Pages\Folder::load( $info['page_seo_name'], 'folder_name' )->parent_id )
{
$info['page_seo_name'] = \IPS\Http\Url::seoTitle( $info['page_name'] . '-' . $info['page_id'] );
}
@@ -598,7 +622,7 @@ class _Cms extends Core
$info['container_parent_id'] = 0;
}
if ( !isset( $info['container_type'] ) OR !in_array( $info['container_type'], array( 'block' ) ) )
if ( !isset( $info['container_type'] ) OR !\in_array( $info['container_type'], array( 'block' ) ) )
{
$info['container_type'] = 'block';
}
@@ -621,7 +645,7 @@ class _Cms extends Core
$inserted_id = \IPS\Db::i()->insert( 'cms_containers', $info );
$this->software->app->addLink( $inserted_id, $id, 'cms_containers' );
\IPS\Db::i()->update( 'cms_containers', array( "container_parent_id" => $inserted_id ), array( "container_conv_parent=? AND container_conv_parent<>?", $id, 0 ) );
\IPS\Db::i()->update( 'cms_containers', array( "container_parent_id" => $inserted_id ), array( "container_conv_parent=?", $id ) );
return $inserted_id;
}
@@ -677,7 +701,7 @@ class _Cms extends Core
if ( isset( $info['block_config'] ) )
{
if ( !is_array( $info['block_config'] ) )
if ( !\is_array( $info['block_config'] ) )
{
$info['block_config'] = json_decode( $info['block_config'], TRUE );
}
@@ -688,7 +712,7 @@ class _Cms extends Core
}
else
{
if ( !isset( $info['block_config']['editor'] ) OR !in_array( $info['block_config']['editor'], array( 'editor', 'html', 'php' ) ) )
if ( !isset( $info['block_config']['editor'] ) OR !\in_array( $info['block_config']['editor'], array( 'editor', 'html', 'php' ) ) )
{
$info['block_config']['editor'] = 'html';
}
@@ -795,7 +819,7 @@ class _Cms extends Core
}
/* No fields - we need at least one */
if ( !count( $fields ) )
if ( !\count( $fields ) )
{
$this->software->app->log( 'cms_database_no_fields', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['database_id'] );
return FALSE;
@@ -874,7 +898,7 @@ class _Cms extends Core
if ( !isset( $info['database_key'] ) )
{
$info['database_key'] = \IPS\Http\Url::seoTitle( $name );
$info['database_key'] = \IPS\Http\Url::seoTitle( $name ) . '_' . time();
}
/* Zero Defaults */
@@ -897,7 +921,7 @@ class _Cms extends Core
if ( isset( $info['database_options'] ) )
{
if ( is_array( $info['database_options'] ) )
if ( \is_array( $info['database_options'] ) )
{
$bitoptions = 0;
@@ -919,7 +943,7 @@ class _Cms extends Core
if ( isset( $info['database_fixed_field_perms'] ) )
{
if ( is_array( $info['database_fixed_field_perms'] ) )
if ( \is_array( $info['database_fixed_field_perms'] ) )
{
$info['database_fixed_field_perms'] = json_encode( $info['database_fixed_field_perms'] );
}
@@ -944,7 +968,7 @@ class _Cms extends Core
if ( isset( $info['database_featured_settings'] ) )
{
if ( is_array( $info['database_featured_settings'] ) )
if ( \is_array( $info['database_featured_settings'] ) )
{
$info['database_featured_settings'] = json_encode( $info['database_featured_settings'] );
}
@@ -963,7 +987,7 @@ class _Cms extends Core
if ( isset( $info['database_fixed_field_settings'] ) )
{
if ( is_array( $info['database_fixed_field_settings'] ) )
if ( \is_array( $info['database_fixed_field_settings'] ) )
{
$info['database_fixed_field_settings'] = json_encode( $info['database_fixed_field_settings'] );
}
@@ -1046,7 +1070,7 @@ class _Cms extends Core
if ( isset( $info['database_tags_predefined'] ) )
{
if ( is_array( $info['database_tags_predefined'] ) )
if ( \is_array( $info['database_tags_predefined'] ) )
{
$info['database_tags_predefined'] = implode( ',', $info['database_tags_predefined'] );
}
@@ -1094,7 +1118,7 @@ class _Cms extends Core
/* We already know this */
$field['field_database_id'] = $inserted_id;
if ( !in_array( $field['field_type'], $validFields ) )
if ( !\in_array( $field['field_type'], $validFields ) )
{
continue;
}
@@ -1205,20 +1229,20 @@ class _Cms extends Core
if ( isset( $field['field_format_opts'] ) )
{
$opts = array();
if ( !is_array( $field['field_format_opts'] ) )
if ( !\is_array( $field['field_format_opts'] ) )
{
$field['field_format_opts'] = json_decode( $field['field_format_opts'], TRUE );
}
foreach( $field['field_format_opts'] AS $key => $value )
{
if ( in_array( $value, array( 'strtolower', 'strtoupper', 'ucfirst', 'ucwords', 'punct', 'numerical', 'bold', 'italic' ) ) )
if ( \in_array( $value, array( 'strtolower', 'strtoupper', 'ucfirst', 'ucwords', 'punct', 'numerical', 'bold', 'italic' ) ) )
{
$opts[$key] = $value;
}
}
if ( count( $opts ) )
if ( \count( $opts ) )
{
$field['field_format_opts'] = json_encode( $opts );
}
@@ -1249,7 +1273,7 @@ class _Cms extends Core
if ( isset( $field['field_allowed_extensions'] ) )
{
if ( is_array( $field['field_allowed_extensions'] ) )
if ( \is_array( $field['field_allowed_extensions'] ) )
{
$field['field_allowed_extensions'] = json_encode( $field['field_allow_extensions'] );
}
@@ -1281,7 +1305,7 @@ class _Cms extends Core
if ( isset( $field['field_display_json'] ) )
{
if ( is_array( $field['field_display_json'] ) )
if ( \is_array( $field['field_display_json'] ) )
{
$field['field_display_json'] = json_encode( $field['field_display_json'] );
}
@@ -1329,7 +1353,7 @@ class _Cms extends Core
$fieldsInserted[$fieldInsertedId] = array( 'type' => $field['field_type'], 'multiple' => $field['field_is_multiple'], 'max_length' => $field['field_max_length'] );
}
if ( count( $fieldsInserted ) > 0 )
if ( \count( $fieldsInserted ) > 0 )
{
\IPS\Db::i()->update( 'cms_databases', array( 'database_field_title' => $titleField, 'database_field_content' => $contentField ), array( "database_id=?", $inserted_id ) );
\IPS\Lang::saveCustom( 'cms', "content_db_{$inserted_id}", $name );
@@ -1452,7 +1476,7 @@ class _Cms extends Core
if ( $data['type'] != 'Upload' )
{
if ( $columnDefinition['type'] == 'TEXT' )
if ( \in_array( $columnDefinition['type'], [ 'TEXT', 'MEDIUMTEXT' ] ) )
{
\IPS\Db::i()->addIndex( "cms_custom_database_{$inserted_id}", array( 'type' => 'fulltext', 'name' => $columnDefinition['name'], 'columns' => array( $columnDefinition['name'] ) ) );
}
@@ -1586,7 +1610,7 @@ class _Cms extends Core
if ( !isset( $info['category_last_record_seo_name'] ) )
{
if ( !is_null( $info['category_last_record_name'] ) )
if ( !\is_null( $info['category_last_record_name'] ) )
{
$info['category_last_record_seo_name'] = \IPS\Http\Url::seoTitle( $info['category_last_record_name'] );
}
@@ -1628,7 +1652,7 @@ class _Cms extends Core
if ( isset( $info['category_meta_keywords'] ) )
{
if ( is_array( $info['category_meta_keywords'] ) )
if ( \is_array( $info['category_meta_keywords'] ) )
{
$info['category_meta_keywords'] = implode( ',', $info['category_meta_keywords'] );
}
@@ -1733,7 +1757,7 @@ class _Cms extends Core
if ( !isset( $info['category_last_seo_title'] ) )
{
if ( !is_null( $info['category_last_title'] ) )
if ( !\is_null( $info['category_last_title'] ) )
{
$info['category_last_seo_title'] = \IPS\Http\Url::seoTitle( $info['category_last_title'] );
}
@@ -1749,7 +1773,7 @@ class _Cms extends Core
if ( isset( $info['category_fields'] ) )
{
if ( !is_array( $info['category_fields'] ) )
if ( !\is_array( $info['category_fields'] ) )
{
$info['category_fields'] = json_decode( $info['category_fields'], TRUE );
}
@@ -1767,7 +1791,7 @@ class _Cms extends Core
}
}
if ( count( $fields ) )
if ( \count( $fields ) )
{
$info['category_fields'] = json_encode( $fields );
}
@@ -1794,7 +1818,7 @@ class _Cms extends Core
$inserted_id = \IPS\Db::i()->insert( 'cms_database_categories', $info );
$this->software->app->addLink( $inserted_id, $id, 'cms_database_categories' );
\IPS\Db::i()->update( 'cms_database_categories', array( "category_parent_id" => $inserted_id ), array( "category_conv_parent=? AND category_conv_parent<>?", $id, 0 ) );
\IPS\Db::i()->update( 'cms_database_categories', array( "category_parent_id" => $inserted_id ), array( "category_conv_parent=?", $id ) );
\IPS\Db::i()->insert( 'core_permission_index', array( 'app' => 'cms', 'perm_type' => 'categories', 'perm_type_id' => $inserted_id, 'perm_view' => '' ) );
\IPS\Lang::saveCustom( 'cms', "content_cat_name_{$inserted_id}", $info['category_name'] );
@@ -1909,17 +1933,21 @@ class _Cms extends Core
{
$titleField = \IPS\Db::i()->select( 'database_field_title', 'cms_databases', array( "database_id=?", $database ) )->first();
$info['record_dynamic_furl'] = \IPS\Http\Url::seoTitle( $fields['field_' . $titleField] );
$info['record_dynamic_furl'] = \IPS\Http\Url::seoTitle( $fields['field_' . $titleField ] );
}
if ( !isset( $info['record_static_furl'] ) )
{
$info['record_static_furl'] = NULL;
}
else
{
$info['record_static_furl'] = \IPS\Http\Url::seoTitle( $info['record_static_furl'] );
}
if ( isset( $info['record_meta_keywords'] ) )
{
if ( is_array( $info['record_meta_keywords'] ) )
if ( \is_array( $info['record_meta_keywords'] ) )
{
$info['record_meta_keywords'] = implode( ',', $info['record_meta_keywords'] );
}
@@ -1970,7 +1998,7 @@ class _Cms extends Core
}
/* Last comment and last review dates cannot be in the future */
if( in_array( $currentDate, array( 'record_last_comment', 'record_last_review' ) ) AND $info[ $currentDate ] > time() )
if( \in_array( $currentDate, array( 'record_last_comment', 'record_last_review' ) ) AND $info[ $currentDate ] > time() )
{
$info[ $currentDate ] = time();
}
@@ -2015,7 +2043,7 @@ class _Cms extends Core
$info['record_last_comment_name'] = NULL;
}
if ( isset( $info['record_image'] ) AND ( !is_null( $imagepath ) OR !is_null( $imagedata ) ) )
if ( isset( $info['record_image'] ) AND ( !\is_null( $imagepath ) OR !\is_null( $imagedata ) ) )
{
$container = NULL;
if( $info['record_saved'] )
@@ -2025,7 +2053,7 @@ class _Cms extends Core
try
{
if ( is_null( $imagedata ) AND !is_null( $imagepath ) )
if ( \is_null( $imagedata ) AND !\is_null( $imagepath ) )
{
$imagedata = @file_get_contents( $imagepath );
$imagepath = NULL;
@@ -2138,7 +2166,7 @@ class _Cms extends Core
{
$return = array();
if ( count( $fieldInfo ) )
if ( \count( $fieldInfo ) )
{
foreach( $fieldInfo as $key => $value )
{
@@ -2146,7 +2174,7 @@ class _Cms extends Core
{
$id = str_replace( 'field_', '', $matches[1] );
}
else if ( is_numeric( $key ) )
else if ( \is_numeric( $key ) )
{
$id = $key;
}
@@ -2482,13 +2510,13 @@ class _Cms extends Core
if ( isset( $info['review_votes_data'] ) )
{
if ( !is_array( $info['review_votes_data'] ) )
if ( !\is_array( $info['review_votes_data'] ) )
{
$info['review_votes_data'] = json_decode( $info['review_votes_data'], TRUE );
}
$newVoters = array();
if ( !is_null( $info['review_votes_data'] ) AND count( $info['review_votes_data'] ) )
if ( !\is_null( $info['review_votes_data'] ) AND \count( $info['review_votes_data'] ) )
{
foreach( $info['review_votes_data'] AS $member => $vote )
{
@@ -2505,7 +2533,7 @@ class _Cms extends Core
}
}
if ( count( $newVoters ) )
if ( \count( $newVoters ) )
{
$info['review_votes_data'] = json_encode( $newVoters );
}
@@ -2521,19 +2549,19 @@ class _Cms extends Core
if ( !isset( $info['review_votes_total'] ) )
{
if ( is_null( $info['review_votes_data'] ) )
if ( \is_null( $info['review_votes_data'] ) )
{
$info['review_votes_total'] = 0;
}
else
{
$info['review_votes_total'] = count( json_decode( $info['review_votes_data'], TRUE ) );
$info['review_votes_total'] = \count( json_decode( $info['review_votes_data'], TRUE ) );
}
}
if ( !isset( $info['review_votes_helpful'] ) )
{
if ( is_null( $info['review_votes_data'] ) )
if ( \is_null( $info['review_votes_data'] ) )
{
$info['review_votes_helpful'] = 0;
}
@@ -2612,7 +2640,7 @@ class _Cms extends Core
$inserted_id = \IPS\Db::i()->insert( 'cms_media_folders', $info );
$this->software->app->addLink( $inserted_id, $id, 'cms_media_folders' );
\IPS\Db::i()->update( 'cms_media_folders', array( "media_folder_parent" => $inserted_id ), array( "media_conv_parent=? AND media_conv_parent<>?", $id, 0 ) );
\IPS\Db::i()->update( 'cms_media_folders', array( "media_folder_parent" => $inserted_id ), array( "media_conv_parent=?", $id ) );
return $inserted_id;
}
@@ -2633,7 +2661,7 @@ class _Cms extends Core
return FALSE;
}
if ( is_null( $filepath ) AND is_null( $filedata ) )
if ( \is_null( $filepath ) AND \is_null( $filedata ) )
{
$this->software->app->log( 'cms_media_file_no_file', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['media_id'] );
return FALSE;
@@ -2657,7 +2685,7 @@ class _Cms extends Core
if ( !isset( $info['media_filename'] ) )
{
if ( !is_null( $filepath ) )
if ( !\is_null( $filepath ) )
{
$name = explode( '/', $filepath );
$name = array_pop( $name );
@@ -2698,7 +2726,7 @@ class _Cms extends Core
try
{
if ( is_null( $filedata ) AND !is_null( $filepath ) )
if ( \is_null( $filedata ) AND !\is_null( $filepath ) )
{
$filedata = @file_get_contents( $filepath );
$filepath = NULL;
@@ -2747,6 +2775,7 @@ class _Cms extends Core
* @param array $map Attachment Map Data
* @param string|NULL $filepath Path to the file, or NULL.
* @param string|NULL $filedata Binary data for the file, or NULL.
* @param string|NULL $thumbnailpath Path to the thumbnail, or NULL.
* @return integer|boolean The ID of the newly inserted attachment, or FALSE on failure.
*/
public function convertAttachment( $info=array(), $map=array(), $filepath=NULL, $filedata=NULL, $thumbnailpath = NULL )
@@ -2757,19 +2786,47 @@ class _Cms extends Core
$map['id1_from_parent'] = FALSE;
$map['id2_from_parent'] = FALSE;
$map['id3_skip_link'] = TRUE;
$map['location_key'] = "cms_Records";
if ( \substr( $map['id3'], -1, 7 ) == '-review' )
$map['location_key'] = "cms_Records" . $database;
if( empty( $map['id2_type'] ) )
{
$map['id2_type'] = 'cms_database_reviews';
}
else
{
$map['id2_type'] = 'cms_database_comments';
if ( \substr( $map['id3'], -1, 7 ) == '-review' )
{
$map['id2_type'] = 'cms_database_reviews';
}
else
{
$map['id2_type'] = 'cms_database_comments';
}
}
$map['id3'] = $database;
return parent::convertAttachment( $info, $map, $filepath, $filedata, $thumbnailpath );
}
/**
* Convert a Tag - CMS, we need to verify the database in a different way that doesn't require it to be on a page
*
* @param array $info Data to insert
* @return boolean|integer The ID of the newly inserted tag, or FALSE on failure.
* @note Like Follows, this should be done when the actual content it's attached too is being converted.
* @note core_tags_cache and core_tags_perms need to be populated by the converter.
*/
public function convertTag( $info=array() )
{
$classname = 'IPS\cms\\' . ucfirst( $info['tag_meta_area'] );
if( !class_exists( $classname ) )
{
$this->software->app->log( 'tag_area_invalid_cms', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['tag_id'] ?? NULL );
return FALSE;
}
/* Set this as a validated content class */
$this->_ipsTagContentClass = $classname;
return parent::convertTag( $info );
}
}
File diff suppressed because it is too large. Load diff
@@ -5,19 +5,22 @@
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @since 21 Jan 2015
*/
namespace IPS\convert\Library;
/* 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;
}
/**
* Invision Downloads Converter
*/
class _Downloads extends Core
{
/**
@@ -34,6 +37,7 @@ class _Downloads extends Core
public function menuRows( $rowCounts=FALSE )
{
$return = array();
$extraRows = $this->software->extraMenuRows();
foreach( $this->getConvertableItems() as $k => $v )
{
@@ -45,7 +49,7 @@ class _Downloads extends Core
'step_title' => 'convert_downloads_cfields',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'downloads_cfields' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'downloads_cfields',
);
@@ -64,7 +68,7 @@ class _Downloads extends Core
'step_title' => 'convert_downloads_categories',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'downloads_categories' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => $dependencies,
'link_type' => 'downloads_categories',
);
@@ -87,7 +91,7 @@ class _Downloads extends Core
'step_title' => 'convert_downloads_files',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'downloads_files' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 250,
'per_cycle' => 10,
'dependencies' => $dependencies,
'link_type' => 'downloads_files',
'requires_rebuild' => TRUE
@@ -100,7 +104,7 @@ class _Downloads extends Core
'step_title' => 'convert_downloads_comments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'downloads_comments' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1500,
'per_cycle' => 200,
'dependencies' => array( 'convertDownloadsFiles' ),
'link_type' => 'downloads_comments',
'requires_rebuild' => TRUE
@@ -113,7 +117,7 @@ class _Downloads extends Core
'step_title' => 'convert_downloads_reviews',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'downloads_reviews' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1500,
'per_cycle' => 200,
'dependencies' => array( 'convertDownloadsFiles' ),
'link_type' => 'downloads_reviews',
'requires_rebuild' => TRUE
@@ -126,7 +130,7 @@ class _Downloads extends Core
'step_method' => 'convertClubDownloadsCategories',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'downloads_categories', array( "cclub_id IS NOT NULL" ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'per_cycle' => 200,
'dependencies' => array( 'convertClubs' ),
'link_type' => 'core_club_downloads_categories',
);
@@ -138,7 +142,7 @@ class _Downloads extends Core
'step_method' => 'convertClubDownloadsFiles',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'downloads_files', array( \IPS\Db::i()->in( 'file_category_id', \IPS\Db::i()->select( 'cid', 'downloads_categories', array( "cclub_id IS NOT NULL" ) ) ) ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 10,
'dependencies' => array( 'convertClubDownloadsCategories' ),
'link_type' => 'core_club_downloads_files'
);
@@ -150,7 +154,7 @@ class _Downloads extends Core
'step_method' => 'convertClubDownloadsComments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'downloads_comments', array( \IPS\Db::i()->in( 'comment_file_id', \IPS\Db::i()->select( 'file_id', 'downloads_files', array( \IPS\Db::i()->in( 'file_category_id', \IPS\Db::i()->select( 'cid', 'downloads_categories', array( "cclub_id IS NOT NULL" ) ) ) ) ) ) ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'per_cycle' => 200,
'dependencies' => array( 'convertClubDownloadsFiles' ),
'link_type' => 'core_club_downloads_comments',
);
@@ -162,27 +166,46 @@ class _Downloads extends Core
'step_method' => 'convertClubDownloadsReviews',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'downloads_files_reviews', array( \IPS\Db::i()->in( 'review_file_id', \IPS\Db::i()->select( 'file_id', 'downloads_files', array( \IPS\Db::i()->in( 'file_category_id', \IPS\Db::i()->select( 'cid', 'downloads_categories', array( "cclub_id IS NOT NULL" ) ) ) ) ) ) ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'per_cycle' => 200,
'dependencies' => array( 'convertClubDownloadsFiles' ),
'link_type' => 'core_club_downloads_reviews',
);
break;
case 'convertAttachments':
$dependencies = array( 'convertDownloadsFiles' );
if ( array_key_exists( 'convertDownloadsComments', $this->getConvertableItems() ) )
{
$dependencies[] = 'convertDownloadsComments';
}
if ( array_key_exists( 'convertDownloadsReviews', $this->getConvertableItems() ) )
{
$dependencies[] = 'convertDownloadsReviews';
}
$return[ $k ] = array(
'step_method' => 'convertAttachments',
'step_title' => 'convert_attachments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'core_attachments_map', array( "location_key=?", 'downloads_Downloads' ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'dependencies' => array( 'convertDownloadsFiles', 'convertDownloadsComments', 'convertDownloadsReviews' ),
'per_cycle' => 10,
'dependencies' => $dependencies,
'link_type' => 'core_attachments',
);
break;
}
}
$return = $this->software->extraMenuRows( $return );
/* Append any extra steps immediately to retain ordering */
if( isset( $v['extra_steps'] ) )
{
foreach( $v['extra_steps'] as $extra )
{
$return[ $extra ] = $extraRows[ $extra ];
}
}
}
/* Run the queries if we want row counts */
if( $rowCounts )
@@ -196,12 +219,13 @@ class _Downloads extends Core
/**
* Returns an array of tables that need to be truncated when Empty Local Data is used
*
* @param string $method Method to truncate
* @return array
*/
protected function truncate( $method )
{
$return = array();
$classname = get_class( $this->software );
$classname = \get_class( $this->software );
if( $classname::canConvert() === NULL )
{
@@ -231,7 +255,8 @@ class _Downloads extends Core
$return['convertDownloadsFiles'] = array(
'downloads_files' => NULL,
'downloads_files_records' => NULL,
'core_tags' => array( 'tag_meta_app=? AND tag_meta_area=?', 'downloads', 'downloads' )
'core_tags' => array( 'tag_meta_app=? AND tag_meta_area=?', 'downloads', 'downloads' ),
'core_reputation_index' => array( 'app=? AND type=?', 'downloads', 'file_id' ),
);
break;
@@ -298,7 +323,7 @@ class _Downloads extends Core
return FALSE;
}
if ( !isset( $info['cf_type'] ) OR !in_array( $info['cf_type'], $validFields ) )
if ( !isset( $info['cf_type'] ) OR !\in_array( $info['cf_type'], $validFields ) )
{
$this->software->app->log( 'downloads_cfield_invalid_type', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['cf_id'] );
return FALSE;
@@ -306,7 +331,7 @@ class _Downloads extends Core
if ( isset( $info['cf_content'] ) )
{
if ( is_array( $info['cf_content'] ) )
if ( \is_array( $info['cf_content'] ) )
{
$info['cf_content'] = json_encode( $info['cf_content'] );
}
@@ -430,7 +455,7 @@ class _Downloads extends Core
if ( $info['cf_type'] != 'Upload' )
{
if ( $columnDefinition['type'] == 'TEXT' )
if ( \in_array( $columnDefinition['type'], [ 'TEXT', 'MEDIUMTEXT' ] ) )
{
\IPS\Db::i()->addIndex( 'downloads_ccontent', array( 'type' => 'fulltext', 'name' => $columnDefinition['name'], 'columns' => array( $columnDefinition['name'] ) ) );
}
@@ -454,7 +479,7 @@ class _Downloads extends Core
{
$return = array( 'file_id' => $file_id );
if ( count( $fieldInfo ) )
if ( \count( $fieldInfo ) )
{
foreach( $fieldInfo as $key => $value )
{
@@ -549,13 +574,13 @@ class _Downloads extends Core
if ( isset( $info['ccfields'] ) )
{
if ( !is_array( $info['ccfields'] ) )
if ( !\is_array( $info['ccfields'] ) )
{
$info['ccfields'] = explode( ',', $info['ccfields'] );
}
$newCfields = array();
if ( count( $info['ccfields'] ) )
if ( \count( $info['ccfields'] ) )
{
foreach( $info['ccfields'] AS $field )
{
@@ -570,7 +595,7 @@ class _Downloads extends Core
}
}
if ( count( $newCfields ) )
if ( \count( $newCfields ) )
{
$info['ccfields'] = implode( ',', $newCfields );
}
@@ -611,7 +636,7 @@ class _Downloads extends Core
if ( isset( $info['ctypes'] ) )
{
if ( is_array( $info['ctypes'] ) )
if ( \is_array( $info['ctypes'] ) )
{
$info['ctypes'] = implode( ',', $info['ctypes'] );
}
@@ -621,7 +646,7 @@ class _Downloads extends Core
$info['ctypes'] = NULL;
}
if ( !isset( $info['csortorder'] ) OR !in_array( $info['csortoder'], array( 'updated', 'last_comment', 'title', 'rating', 'date', 'num_comments', 'num_reviews', 'views' ) ) )
if ( !isset( $info['csortorder'] ) OR !\in_array( $info['csortoder'], array( 'updated', 'last_comment', 'title', 'rating', 'date', 'num_comments', 'num_reviews', 'views' ) ) )
{
$info['csortorder'] = 'updated';
}
@@ -638,7 +663,7 @@ class _Downloads extends Core
if ( isset( $info['cmaxdims'] ) )
{
if ( is_array( $info['cmaxdims'] ) )
if ( \is_array( $info['cmaxdims'] ) )
{
$info['cmaxdims'] = implode( 'x', $info['cmaxdims'] );
}
@@ -714,7 +739,7 @@ class _Downloads extends Core
\IPS\Lang::saveCustom( 'downloads', "downloads_category_{$inserted_id}", $name );
\IPS\Lang::saveCustom( 'downloads', "downloads_category_{$inserted_id}_desc", $desc );
\IPS\Db::i()->update( 'downloads_categories', array( "cparent" => $inserted_id ), array( "cconv_parent=? AND cconv_parent<>?", $id, 0 ) );
\IPS\Db::i()->update( 'downloads_categories', array( "cparent" => $inserted_id ), array( "cconv_parent=?", $id ) );
\IPS\Db::i()->insert( 'core_permission_index', array( 'app' => 'downloads', 'perm_type' => 'category', 'perm_type_id' => $inserted_id, 'perm_view' => '' ) );
if ( $info['cclub_id'] )
@@ -748,7 +773,7 @@ class _Downloads extends Core
return FALSE;
}
if ( !count( $records ) )
if ( !\count( $records ) )
{
$this->software->app->log( 'downloads_file_no_records', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['file_id'] );
return FALSE;
@@ -968,6 +993,33 @@ class _Downloads extends Core
{
$info['file_last_review'] = $info['file_submitted'];
}
if ( isset( $info['file_edit_time'] ) )
{
if ( $info['file_edit_time'] instanceof \IPS\DateTime )
{
$info['file_edit_time'] = $info['file_edit_time']->getTimestamp();
}
}
else
{
$info['file_edit_time'] = NULL;
}
if ( !isset( $info['file_edit_name'] ) )
{
$info['file_edit_name'] = NULL;
}
if ( !isset( $info['file_edit_reason'] ) )
{
$info['file_edit_reason'] = '';
}
if ( !isset( $info['file_append_edit'] ) )
{
$info['file_append_edit'] = 0;
}
$id = $info['file_id'];
unset( $info['file_id'] );
@@ -992,7 +1044,7 @@ class _Downloads extends Core
$record['record_link_type'] = NULL;
$record['record_no_watermark'] = NULL;
if ( !isset( $record['record_type'] ) OR !in_array( $record['record_type'], array( 'upload', 'ssupload', 'link' ) ) )
if ( !isset( $record['record_type'] ) OR !\in_array( $record['record_type'], array( 'upload', 'ssupload', 'link' ) ) )
{
$record['record_type'] = 'upload';
}
@@ -1009,7 +1061,7 @@ class _Downloads extends Core
if ( !isset( $record['record_realname'] ) )
{
if ( isset( $record['file_path'] ) AND !is_null( $record['file_path'] ) )
if ( isset( $record['file_path'] ) AND !\is_null( $record['file_path'] ) )
{
$fileName = explode( '/', $record['file_path'] );
$fileName = array_pop( $fileName );
@@ -1343,13 +1395,13 @@ class _Downloads extends Core
if ( isset( $info['review_votes_data'] ) )
{
if ( !is_array( $info['review_votes_data'] ) )
if ( !\is_array( $info['review_votes_data'] ) )
{
$info['review_votes_data'] = json_decode( $info['review_votes_data'], TRUE );
}
$newVoters = array();
if ( !is_null( $info['review_votes_data'] ) AND count( $info['review_votes_data'] ) )
if ( !\is_null( $info['review_votes_data'] ) AND \count( $info['review_votes_data'] ) )
{
foreach( $info['review_votes_data'] as $member => $vote )
{
@@ -1366,7 +1418,7 @@ class _Downloads extends Core
}
}
if ( count( $newVoters ) )
if ( \count( $newVoters ) )
{
$info['review_votes_data'] = json_encode( $newVoters );
}
@@ -1382,19 +1434,19 @@ class _Downloads extends Core
if ( !isset( $info['review_votes'] ) )
{
if ( is_null( $info['review_votes_data'] ) )
if ( \is_null( $info['review_votes_data'] ) )
{
$info['review_votes'] = 0;
}
else
{
$info['review_votes'] = count( json_decode( $info['review_votes_data'], TRUE ) );
$info['review_votes'] = \count( json_decode( $info['review_votes_data'], TRUE ) );
}
}
if ( !isset( $info['review_votes_helpful'] ) )
{
if ( is_null( $info['review_votes_data'] ) )
if ( \is_null( $info['review_votes_data'] ) )
{
$info['review_votes_helpful'] = 0;
}
@@ -1439,6 +1491,7 @@ class _Downloads extends Core
* @param array $map Map Data to insert
* @param string|NULL $filepath Path to the file, or NULL.
* @param string|NULL $filedata Binary data for the file, or NULL.
* @param string|NULL $thumbnailpath Path to thumbnail, or NULL.
* @return integer|boolean The ID of the newly inserted attachment, or FALSE on failure.
*/
public function convertAttachment( $info=array(), $map=array(), $filepath=NULL, $filedata=NULL, $thumbnailpath = NULL )
@@ -1453,7 +1506,7 @@ class _Downloads extends Core
$info['id3'] = NULL;
}
if ( is_null( $info['id3'] ) OR $info['id3'] != 'review' )
if ( \is_null( $info['id3'] ) OR $info['id3'] != 'review' )
{
$map['id2_type'] = 'downloads_comments';
}
+89 -208
View File
@@ -5,21 +5,22 @@
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @since 21 Jan 2015
*/
namespace IPS\convert\Library;
/* 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;
}
/**
* Inherit from the Core Library so we can access or overload methods as needed (for example, we do not need to redeclare convertAttachments again here, but we can overload to do extra things if needed).
* Invision Forums Converter
* @note We must extend the Core Library here so we can access methods like convertAttachment, convertFollow, etc
*/
class _Forums extends Core
{
@@ -37,7 +38,8 @@ class _Forums extends Core
public function menuRows( $rowCounts=FALSE )
{
$return = array();
$classname = get_class( $this->software );
$classname = \get_class( $this->software );
$extraRows = $this->software->extraMenuRows();
foreach( $this->getConvertableItems() as $k => $v )
{
@@ -49,7 +51,7 @@ class _Forums extends Core
'step_method' => 'convertForumsForums',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'forums_forums' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'forums_forums',
);
@@ -61,7 +63,7 @@ class _Forums extends Core
'step_method' => 'convertForumsTopics',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'per_cycle' => 200,
'dependencies' => array( 'convertForumsForums' ),
'link_type' => 'forums_topics',
);
@@ -73,7 +75,7 @@ class _Forums extends Core
'step_method' => 'convertForumsPosts',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'forums_posts' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'per_cycle' => 200,
'dependencies' => array( 'convertForumsTopics' ),
'link_type' => 'forums_posts',
'requires_rebuild' => TRUE
@@ -86,7 +88,7 @@ class _Forums extends Core
'step_method' => 'convertForumsArchivePosts',
'ips_rows' => \IPS\forums\Topic\ArchivedPost::db()->select( 'COUNT(*)', 'forums_archive_posts' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'per_cycle' => 200,
'dependencies' => array( 'convertForumsTopics' ),
'link_type' => 'forums_posts',
);
@@ -98,7 +100,7 @@ class _Forums extends Core
'step_method' => 'convertForumsTopicMultimods',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'forums_topic_mmod' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array( 'convertForumsForums' ),
'link_type' => 'forums_topic_mmod',
);
@@ -110,7 +112,7 @@ class _Forums extends Core
'step_method' => 'convertForumsRssImports',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'forums_rss_import' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array( 'convertForumsForums' ),
'link_type' => 'forums_rss_import',
);
@@ -122,7 +124,7 @@ class _Forums extends Core
'step_method' => 'convertForumsRssImported',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'forums_rss_imported' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertForumsTopics', 'convertForumsRssImports' ),
'link_type' => 'forums_rss_imported',
);
@@ -134,7 +136,7 @@ class _Forums extends Core
'step_method' => 'convertForumsQuestionRatings',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'forums_question_ratings' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertForumsTopics' ),
'link_type' => 'forums_question_ratings',
);
@@ -146,7 +148,7 @@ class _Forums extends Core
'step_method' => 'convertForumsAnswerRatings',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'forums_answer_ratings' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertForumsPosts' ),
'link_type' => 'forums_answer_ratings',
);
@@ -158,7 +160,7 @@ class _Forums extends Core
'step_method' => 'convertAttachments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'core_attachments_map', array( "location_key=?", 'forums_Forums' ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 50,
'per_cycle' => 10,
'dependencies' => array( 'convertForumsPosts' ),
'link_type' => 'core_attachments',
);
@@ -170,7 +172,7 @@ class _Forums extends Core
'step_method' => 'convertClubForums',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'forums_forums', array( "club_id IS NOT NULL" ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertForumsForums' ),
'link_type' => 'core_club_forums'
);
@@ -182,7 +184,7 @@ class _Forums extends Core
'step_method' => 'convertClubTopics',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(tid)', 'forums_topics', array( 'forum_id IN ( ' . (string) \IPS\Db::i()->select( 'id', 'forums_forums', array( "club_id IS NOT NULL" ) ) . ')' ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'per_cycle' => 200,
'dependencies' => array( 'convertClubForums' ),
'link_type' => 'core_club_topics'
);
@@ -196,15 +198,22 @@ class _Forums extends Core
->join( 'forums_topics', 'forums_topics.forum_id=forums_forums.id')
->join( 'forums_posts', 'forums_posts.topic_id=forums_topics.tid'),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'per_cycle' => 200,
'dependencies' => array( 'convertClubTopics' ),
'link_type' => 'core_club_posts'
);
break;
}
}
$return = $this->software->extraMenuRows( $return );
/* Append any extra steps immediately to retain ordering */
if( isset( $v['extra_steps'] ) )
{
foreach( $v['extra_steps'] as $extra )
{
$return[ $extra ] = $extraRows[ $extra ];
}
}
}
/* Run the queries if we want row counts */
if( $rowCounts )
@@ -235,12 +244,13 @@ class _Forums extends Core
/**
* Returns an array of tables that need to be truncated when Empty Local Data is used
*
* @param string $method Method to truncate
* @return array
*/
protected function truncate( $method )
{
$return = array();
$classname = get_class( $this->software );
$classname = \get_class( $this->software );
if( $classname::canConvert() === NULL )
{
@@ -457,7 +467,13 @@ class _Forums extends Core
{
try
{
$position = \IPS\Db::i()->select( 'MAX(position)', 'forums_forums', array( "parent_id=?", $info['parent_id'] ) )->first();
$where = array();
if ( isset( $info['parent_id'] ) )
{
/* Clubs may not have a parent */
$where = array( "parent_id=?", $info['parent_id'] );
}
$position = \IPS\Db::i()->select( 'MAX(position)', 'forums_forums', $where )->first();
}
catch( \UnderflowException $e )
{
@@ -475,7 +491,7 @@ class _Forums extends Core
if ( isset( $info['password_override'] ) )
{
/* Array? */
if ( !is_array( $info['password_override'] ) )
if ( !\is_array( $info['password_override'] ) )
{
$info['password_override'] = explode( ',', $info['password_override'] );
}
@@ -542,7 +558,7 @@ class _Forums extends Core
if ( !isset( $info['redirect_on'] ) )
{
if ( !is_null( $info['redirect_url'] ) )
if ( !\is_null( $info['redirect_url'] ) )
{
$info['redirect_on'] = 1;
}
@@ -559,7 +575,7 @@ class _Forums extends Core
if ( !isset( $info['sub_can_post'] ) )
{
if ( $info['parent_id'] == -1 )
if ( isset( $info['parent_id'] ) AND $info['parent_id'] == -1 )
{
$info['sub_can_post'] = 0;
}
@@ -609,7 +625,7 @@ class _Forums extends Core
if ( !isset( $info['seo_last_title'] ) )
{
if ( !is_null( $info['last_title'] ) )
if ( !\is_null( $info['last_title'] ) )
{
$info['seo_last_title'] = \IPS\Http\Url::seoTitle( $info['last_title'] );
}
@@ -621,7 +637,7 @@ class _Forums extends Core
if ( !isset( $info['seo_last_name'] ) )
{
if ( !is_null( $info['last_poster_name'] ) )
if ( !\is_null( $info['last_poster_name'] ) )
{
$info['seo_last_name'] = \IPS\Http\Url::seoTitle( $info['last_poster_name'] );
}
@@ -646,6 +662,11 @@ class _Forums extends Core
}
$info['forums_bitoptions'] = $bitoptions;
}
elseif( isset( $info['ips_forums_bitoptions'] ) )
{
$info['forums_bitoptions'] = $info['ips_forums_bitoptions'];
unset( $info['ips_forums_bitoptions'] );
}
if ( !isset( $info['disable_sharelinks'] ) )
{
@@ -681,12 +702,12 @@ class _Forums extends Core
{
if ( $info['qa_rate_questions'] != '*' )
{
if ( !is_array( $info['qa_rate_questions'] ) )
if ( !\is_array( $info['qa_rate_questions'] ) )
{
$info['qa_rate_questions'] = explode( ',', $info['qa_rate_questions'] );
}
if ( count( $info['qa_rate_questions'] ) )
if ( \count( $info['qa_rate_questions'] ) )
{
$qaQuestionGroups = array();
foreach( $info['qa_rate_questions'] AS $group )
@@ -701,7 +722,7 @@ class _Forums extends Core
}
}
if ( count( $qaQuestionGroups ) )
if ( \count( $qaQuestionGroups ) )
{
$info['qa_rate_questions'] = implode( ',', $qaQuestionGroups );
}
@@ -725,12 +746,12 @@ class _Forums extends Core
{
if ( $info['qa_rate_answers'] != '*' )
{
if ( !is_array( $info['qa_rate_answers'] ) )
if ( !\is_array( $info['qa_rate_answers'] ) )
{
$info['qa_rate_answers'] = explode( ',', $info['qa_rate_answers'] );
}
if ( count( $info['qa_rate_anwsers'] ) )
if ( \count( $info['qa_rate_anwsers'] ) )
{
$qaAnswerGroups = array();
foreach( $info['qa_rate_answers'] AS $group )
@@ -745,7 +766,7 @@ class _Forums extends Core
}
}
if ( count( $qaAnswerGroups ) )
if ( \count( $qaAnswerGroups ) )
{
$info['qa_rate_answers'] = implode( ',', $qaAnswerGroups );
}
@@ -767,9 +788,9 @@ class _Forums extends Core
try
{
if ( isset( $info['icon'] ) AND ( !is_null( $iconpath ) OR !is_null( $icondata ) ) )
if ( isset( $info['icon'] ) AND ( !\is_null( $iconpath ) OR !\is_null( $icondata ) ) )
{
if ( is_null( $icondata ) AND !is_null( $iconpath ) )
if ( \is_null( $icondata ) AND !\is_null( $iconpath ) )
{
$icondata = file_get_contents( $iconpath );
}
@@ -831,7 +852,7 @@ class _Forums extends Core
\IPS\Lang::saveCustom( 'forums', "forums_forum_{$inserted_id}", $name );
\IPS\Lang::saveCustom( 'forums', "forums_forum_{$inserted_id}_desc", $desc );
\IPS\Db::i()->update( 'forums_forums', array( "parent_id" => $inserted_id ), array( "conv_parent=? AND conv_parent<>?", $id, 0 ) );
\IPS\Db::i()->update( 'forums_forums', array( "parent_id" => $inserted_id ), array( "conv_parent=?", $id ) );
\IPS\Db::i()->insert( 'core_permission_index', array( 'app' => 'forums', 'perm_type' => 'forum', 'perm_type_id' => $inserted_id, 'perm_view' => '' ) );
if ( $info['club_id'] )
@@ -910,7 +931,7 @@ class _Forums extends Core
return FALSE;
}
if ( !isset( $info['state'] ) OR !in_array( $info['state'], array( 'open', 'closed' ) ) )
if ( !isset( $info['state'] ) OR !\in_array( $info['state'], array( 'open', 'closed' ) ) )
{
$info['state'] = 'open';
}
@@ -1009,7 +1030,7 @@ class _Forums extends Core
}
/* Polls - pass off to the core library. Unlike ratings and follows, we need to do this here as we need to know the Poll ID. */
if ( isset( $info['poll_state'] ) AND is_array( $info['poll_state'] ) )
if ( isset( $info['poll_state'] ) AND \is_array( $info['poll_state'] ) )
{
if ( $info['poll_state'] = $this->convertPoll( $info['poll_state']['poll_data'], $info['poll_state']['vote_data'] ) )
{
@@ -1026,6 +1047,13 @@ class _Forums extends Core
$info['last_vote'] = $lastVote;
}
else
{
if ( $info['last_vote'] instanceof \IPS\DateTime )
{
$info['last_vote'] = $info['last_vote']->getTimestamp();
}
}
}
else
{
@@ -1059,7 +1087,7 @@ class _Forums extends Core
if ( isset( $info['moved_to'] ) )
{
if ( !is_array( $info['moved_to'] ) )
if ( !\is_array( $info['moved_to'] ) )
{
list( $topic, $forum ) = explode( '&', $info['moved_to'] );
}
@@ -1086,7 +1114,7 @@ class _Forums extends Core
$forum = NULL;
}
if ( is_null( $topic ) OR is_null( $forum ) )
if ( \is_null( $topic ) OR \is_null( $forum ) )
{
$info['moved_to'] = NULL;
}
@@ -1353,6 +1381,11 @@ class _Forums extends Core
}
$info['post_bwoptions'] = $bitoptions;
}
elseif( isset( $info['ips_post_bwoptions'] ) )
{
$info['post_bwoptions'] = $info['ips_post_bwoptions'];
unset( $info['ips_post_bwoptions'] );
}
if ( isset( $info['pdelete_time'] ) )
{
@@ -1400,7 +1433,7 @@ class _Forums extends Core
$topicUpdate['topic_answered_pid'] = $inserted_id;
}
if ( count( $topicUpdate ) )
if ( \count( $topicUpdate ) )
{
\IPS\Db::i()->update( 'forums_topics', $topicUpdate, array( "tid=?", $info['topic_id'] ) );
}
@@ -1509,12 +1542,12 @@ class _Forums extends Core
$info['mm_enabled'] = 1;
}
if ( !isset( $info['topic_state'] ) OR !in_array( $info['topic_state'], array( 'leave', 'open', 'close' ) ) )
if ( !isset( $info['topic_state'] ) OR !\in_array( $info['topic_state'], array( 'leave', 'open', 'close' ) ) )
{
$info['topic_state'] = 'leave';
}
if ( !isset( $info['topic_pin'] ) OR !in_array( $info['topic_pin'], array( 'leave', 'pin', 'unpin' ) ) )
if ( !isset( $info['topic_pin'] ) OR !\in_array( $info['topic_pin'], array( 'leave', 'pin', 'unpin' ) ) )
{
$info['topic_pin'] = 'leave';
}
@@ -1579,13 +1612,13 @@ class _Forums extends Core
{
if ( $info['mm_forums'] != '*' )
{
if ( !is_array( $info['mm_forums'] ) )
if ( !\is_array( $info['mm_forums'] ) )
{
$info['mm_forums'] = explode( ',', $info['mm_forums'] );
}
$forums = array();
if ( count( $info['mm_forums'] ) )
if ( \count( $info['mm_forums'] ) )
{
foreach( $info['mm_forums'] AS $forum )
{
@@ -1600,7 +1633,7 @@ class _Forums extends Core
}
}
if ( count( $forums ) )
if ( \count( $forums ) )
{
$info['mm_forums'] = implode( ',', $forums );
}
@@ -1615,7 +1648,7 @@ class _Forums extends Core
$info['mm_forums'] = '*';
}
if ( !isset( $info['topic_approve'] ) OR !in_array( $info['topic_approve'], array( 0, 1, 2 ) ) )
if ( !isset( $info['topic_approve'] ) OR !\in_array( $info['topic_approve'], array( 0, 1, 2 ) ) )
{
$info['topic_approve'] = 0;
}
@@ -1645,130 +1678,22 @@ class _Forums extends Core
*/
public function convertForumsRssImport( $info=array() )
{
if ( !isset( $info['rss_import_id'] ) )
{
$this->software->app->log( 'rss_import_missing_ids', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
/* Required Stuff */
if ( !isset( $info['rss_import_url'] ) OR filter_var( $info['rss_import_url'], FILTER_VALIDATE_URL ) === FALSE )
{
$this->software->app->log( 'rss_import_invalid_url', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['rss_import_id'] );
return FALSE;
}
if ( isset( $info['rss_import_forum_id'] ) )
{
try
{
$info['rss_import_forum_id'] = $this->software->app->getLink( $info['rss_import_forum_id'], 'forums_forums' );
}
catch( \OutOfRangeException $e )
{
$this->software->app->log( 'rss_import_missing_forum', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['rss_import_id'] );
return FALSE;
}
}
else
{
$this->software->app->log( 'rss_import_missing_forum', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['rss_import_id'] );
return FALSE;
}
if ( isset( $info['rss_import_mid'] ) )
{
try
{
$info['rss_import_mid'] = $this->software->app->getLink( $info['rss_import_mid'], 'core_members', TRUE );
}
catch( \OutOfRangeException $e )
{
$this->software->app->log( 'rss_import_missing_member', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['rss_import_id'] );
return FALSE;
}
}
else
{
$this->software->app->log( 'rss_import_missing_member', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['rss_import_id'] );
return FALSE;
}
/* Stuff we can use defaults for */
if ( !isset( $info['rss_import_title'] ) )
{
$info['rss_import_title'] = "Untitled Feed {$info['rss_import_id']}";
}
if ( !isset( $info['rss_import_pergo'] ) )
{
$info['rss_import_pergo'] = 10;
}
if ( !isset( $info['rss_import_time'] ) )
{
$info['rss_import_time'] = 30;
}
if ( isset( $info['rss_import_last_import'] ) )
{
if ( $info['rss_import_last_import'] instanceof \IPS\DateTime )
{
$info['rss_import_last_import'] = $info['rss_import_last_import']->getTimestamp();
}
}
else
{
$info['rss_import_last_import'] = time();
}
if ( !isset( $info['rss_import_showlink'] ) )
{
$info['rss_import_showlink'] = "View the full article";
}
$info['rss_import_class'] = 'IPS\\forums\\Topic';
if ( !isset( $info['rss_import_topic_open'] ) )
{
$info['rss_import_topic_open'] = 1;
}
if ( !isset( $info['rss_import_topic_hide'] ) )
{
$info['rss_import_topic_hide'] = 0;
}
if ( !isset( $info['rss_import_topic_pre'] ) )
{
$info['rss_import_topic_pre'] = '';
}
if ( !isset( $info['rss_import_allow_html'] ) )
{
$info['rss_import_allow_html'] = 0;
}
if ( isset( $info['rss_import_auth'] ) AND isset( $info['rss_import_auth_user'] ) AND isset( $info['rss_import_auth_pass'] ) )
{
if ( $info['rss_import_auth'] == 0 )
{
$info['rss_import_auth_user'] = NULL;
$info['rss_import_auth_pass'] = NULL;
}
}
else
{
$info['rss_import_auth'] = 0;
$info['rss_import_auth_user'] = NULL;
$info['rss_import_auth_pass'] = NULL;
}
$id = $info['rss_import_id'];
unset( $info['rss_import_id'] );
$inserted_id = \IPS\Db::i()->insert( 'forums_rss_import', $info );
$this->software->app->addLink( $inserted_id, $id, 'forums_rss_import' );
return $inserted_id;
$info['rss_import_settings'] = array( 'rss_import_topic_open' => $info['rss_import_topic_open'], 'rss_import_topic_hide' => $info['rss_import_topic_hide'] );
unset( $info['rss_import_topic_open'], $info['rss_import_topic_hide'] );
return parent::convertRssImport( $info, 'forums_forums', 'forums_rss_import' );
}
/**
@@ -1779,51 +1704,7 @@ class _Forums extends Core
*/
public function convertForumsRssImported( $info=array() )
{
/* Godspeed */
if ( isset( $info['rss_imported_impid'] ) )
{
try
{
$info['rss_imported_impid'] = $this->software->app->getLink( $info['rss_imported_impid'], 'forums_rss_import' );
}
catch( \OutOfRangeException $e )
{
$this->software->app->log( 'rss_imported_missing_feed', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
}
else
{
$this->software->app->log( 'rss_imported_missing_feed', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
if ( isset( $info['rss_imported_tid'] ) )
{
try
{
$info['rss_imported_tid'] = $this->software->app->getLink( $info['rss_imported_tid'], 'forums_topics' );
}
catch( \OutOfRangeException $e )
{
$this->software->app->log( 'rss_imported_missing_topic', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
}
else
{
$this->software->app->log( 'rss_imported_missing_topic', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
if ( !isset( $info['rss_imported_guid'] ) )
{
$this->software->app->log( 'rss_imported_missing_guid', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
\IPS\Db::i()->insert( 'forums_rss_imported', $info );
return TRUE;
return parent::convertRssImported( $info, 'forums_topics', 'forums_rss_import' );
}
/**
@@ -2073,7 +1954,7 @@ class _Forums extends Core
* @param array $map Array of Map data
* @param NULL|string $filepath The path to the attachment files or NULL if loading from the database.
* @param NULL|string $filedata If loading from the database, the content of the Binary column.
* @param NULL|string $thumnailpath Path to thumbnail image
* @param NULL|string $thumbnailpath Path to thumbnail image
* @return boolean|integer The ID of the newly inserted attachment, or FALSE on failure.
*/
public function convertAttachment( $info=array(), $map=array(), $filepath=NULL, $filedata=NULL, $thumbnailpath=NULL )
@@ -5,19 +5,23 @@
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @since 21 Jan 2015
*/
namespace IPS\convert\Library;
/* 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;
}
/**
* Invision Gallery Converter
* @note We must extend the Core Library here so we can access methods like convertAttachment, convertFollow, etc
*/
class _Gallery extends Core
{
/**
@@ -34,7 +38,7 @@ class _Gallery extends Core
public function menuRows( $rowCounts=FALSE )
{
$return = array();
$classname = get_class( $this->software );
$extraRows = $this->software->extraMenuRows();
foreach( $this->getConvertableItems() as $k => $v )
{
@@ -46,7 +50,7 @@ class _Gallery extends Core
'step_title' => 'convert_gallery_categories',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'gallery_categories' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'gallery_categories',
);
@@ -66,7 +70,7 @@ class _Gallery extends Core
'step_title' => 'convert_gallery_albums',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'gallery_albums' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => $dependencies,
'link_type' => 'gallery_albums',
);
@@ -78,7 +82,7 @@ class _Gallery extends Core
'step_title' => 'convert_gallery_album_comments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'gallery_album_comments' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1500,
'per_cycle' => 200,
'dependencies' => array( 'convertGalleryAlbums' ),
'link_type' => 'gallery_album_comments',
'requires_rebuild' => TRUE
@@ -91,7 +95,7 @@ class _Gallery extends Core
'step_title' => 'convert_gallery_album_reviews',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'gallery_album_reviews' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1500,
'per_cycle' => 200,
'dependencies' => array( 'convertGalleryAlbums' ),
'link_type' => 'gallery_album_reviews',
'requires_rebuild' => TRUE
@@ -117,7 +121,7 @@ class _Gallery extends Core
'step_title' => 'convert_gallery_images',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'gallery_images' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 10,
'dependencies' => $dependencies,
'link_type' => 'gallery_images',
'requires_rebuild' => TRUE
@@ -130,7 +134,7 @@ class _Gallery extends Core
'step_title' => 'convert_gallery_comments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'gallery_comments' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1500,
'per_cycle' => 200,
'dependencies' => array( 'convertGalleryImages' ),
'link_type' => 'gallery_comments',
'requires_rebuild' => TRUE
@@ -143,7 +147,7 @@ class _Gallery extends Core
'step_title' => 'convert_gallery_reviews',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'gallery_reviews' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1500,
'per_cycle' => 200,
'dependencies' => array( 'convertGalleryImages' ),
'link_type' => 'gallery_reviews',
'requires_rebuild' => TRUE
@@ -156,7 +160,7 @@ class _Gallery extends Core
'step_method' => 'convertClubGalleryCategories',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'gallery_categories', array( "category_club_id IS NOT NULL" ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'per_cycle' => 200,
'dependencies' => array( 'convertGalleryImages' ),
'link_type' => 'core_club_gallery_categories'
);
@@ -168,7 +172,7 @@ class _Gallery extends Core
'step_method' => 'convertClubGalleryImages',
'ips_rows' => \IPS\Db::i()->select( 'SUM(category_count_imgs)', 'gallery_categories', array( "category_club_id IS NOT NULL" ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 10,
'dependencies' => array( 'convertClubGalleryCategories' ),
'link_type' => 'core_club_gallery_images'
);
@@ -180,7 +184,7 @@ class _Gallery extends Core
'step_method' => 'convertClubGalleryComments',
'ips_rows' => \IPS\Db::i()->select( 'SUM(category_count_comments)', 'gallery_categories', array( "category_club_id IS NOT NULL" ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'per_cycle' => 200,
'dependencies' => array( 'convertClubGalleryImages' ),
'link_type' => 'core_club_gallery_comments'
);
@@ -192,7 +196,7 @@ class _Gallery extends Core
'step_method' => 'convertClubGalleryReviews',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'gallery_reviews', array( \IPS\Db::i()->in( 'review_image_id', \IPS\Db::i()->select( 'image_id', 'gallery_images', array( \IPS\Db::i()->in( 'image_category_id', \IPS\Db::i()->select( 'category_id', 'gallery_categories', array( "category_club_id IS NOT NULL" ) ) ) ) ) ) ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'per_cycle' => 200,
'dependencies' => array( 'convertClubGalleryImages' ),
'link_type' => 'core_club_gallery_reviews'
);
@@ -216,15 +220,22 @@ class _Gallery extends Core
'step_title' => 'convert_attachments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'core_attachments_map', array( "location_key=?", 'gallery_Images' ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 10,
'dependencies' => $dependencies,
'link_type' => 'core_attachments',
);
break;
}
}
$return = $this->software->extraMenuRows( $return );
/* Append any extra steps immediately to retain ordering */
if( isset( $v['extra_steps'] ) )
{
foreach( $v['extra_steps'] as $extra )
{
$return[ $extra ] = $extraRows[ $extra ];
}
}
}
/* Run the queries if we want row counts */
if( $rowCounts )
@@ -238,12 +249,13 @@ class _Gallery extends Core
/**
* Returns an array of tables that need to be truncated when Empty Local Data is used
*
* @param string $method Method to truncate
* @return array
*/
protected function truncate( $method )
{
$return = array();
$classname = get_class( $this->software );
$classname = \get_class( $this->software );
if( $classname::canConvert() === NULL )
{
@@ -459,7 +471,7 @@ class _Gallery extends Core
\IPS\Lang::saveCustom( 'gallery', "gallery_category_{$inserted_id}", $name );
\IPS\Lang::saveCustom( 'gallery', "gallery_category_{$inserted_id}_desc", $desc );
\IPS\Db::i()->update( 'gallery_categories', array( "category_parent_id" => $inserted_id ), array( "category_conv_parent=? AND category_conv_parent<>?", $id, 0 ) );
\IPS\Db::i()->update( 'gallery_categories', array( "category_parent_id" => $inserted_id ), array( "category_conv_parent=?", $id ) );
\IPS\Db::i()->insert( 'core_permission_index', array( 'app' => 'gallery', 'perm_type' => 'category', 'perm_type_id' => $inserted_id, 'perm_view' => '' ) );
if ( $info['category_club_id'] )
@@ -493,7 +505,7 @@ class _Gallery extends Core
return FALSE;
}
if ( is_null( $category ) )
if ( \is_null( $category ) )
{
if ( isset( $info['album_category_id'] ) )
{
@@ -514,6 +526,16 @@ class _Gallery extends Core
else
{
$info['album_category_id'] = $category;
/* Check the category exists */
try
{
\IPS\gallery\Category::load( $info['album_category_id'] );
}
catch( \OutOfRangeException $e )
{
$info['album_category_id'] = $this->_orphanedAlbumsCategory();
}
}
if ( isset( $info['album_owner_id'] ) )
@@ -545,7 +567,7 @@ class _Gallery extends Core
$info['album_description'] = '';
}
if ( !isset( $info['album_type'] ) OR !in_array( $info['album_type'], array( 1, 2, 3 ) ) )
if ( !isset( $info['album_type'] ) OR !\in_array( $info['album_type'], array( 1, 2, 3 ) ) )
{
$info['album_type'] = 1;
}
@@ -565,7 +587,7 @@ class _Gallery extends Core
$info['album_last_img_date'] = 0;
$info['album_last_x_images'] = NULL;
if ( !isset( $info['album_sort_options'] ) OR !in_array( $info['album_sort_options'], array( 'updated', 'last_comment', 'title', 'rating', 'date', 'num_comments', 'num_reviews', 'views' ) ) )
if ( !isset( $info['album_sort_options'] ) OR !\in_array( $info['album_sort_options'], array( 'updated', 'last_comment', 'title', 'rating', 'date', 'num_comments', 'num_reviews', 'views' ) ) )
{
$info['album_sort_options'] = 'updated';
}
@@ -593,7 +615,7 @@ class _Gallery extends Core
}
$info['album_allowed_access'] = NULL;
if ( !is_null( $socialgroup ) AND is_array( $socialgroup ) )
if ( !\is_null( $socialgroup ) AND \is_array( $socialgroup ) )
{
$socialGroupId = \IPS\Db::i()->insert( 'core_sys_social_groups', array( 'owner_id' => $info['album_owner_id'] ) );
$members = array();
@@ -679,7 +701,7 @@ class _Gallery extends Core
}
/* If we don't have any image to process, just stop here */
if ( is_null( $filedata ) AND ( is_null( $filepath ) OR !file_exists( $filepath ) ) )
if ( \is_null( $filedata ) AND ( \is_null( $filepath ) OR !file_exists( $filepath ) ) )
{
$this->software->app->log( 'gallery_image_missing_image', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['image_id'] );
return FALSE;
@@ -748,7 +770,7 @@ class _Gallery extends Core
$info['image_member_id'] = NULL;
}
if ( is_null( $info['image_member_id'] ) )
if ( \is_null( $info['image_member_id'] ) )
{
try
{
@@ -777,7 +799,7 @@ class _Gallery extends Core
if ( $mime_type === 'application/x-unknown' OR ( \strstr( $mime_type, 'image' ) === FALSE AND \strstr( $mime_type, 'video' ) === FALSE ) )
{
$this->software->app->log( 'gallery_image_invalid_mime_type', __METHOD__, \IPS\convert\App::LOG_WARNING, $image['image_id'] );
$this->software->app->log( 'gallery_image_invalid_mime_type', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['image_id'] );
return FALSE;
}
@@ -787,7 +809,7 @@ class _Gallery extends Core
if ( !isset( $info['image_file_name'] ) )
{
/* If we were passed a path, try and figure it out */
if ( !is_null( $filepath ) )
if ( !\is_null( $filepath ) )
{
$file_name = explode( '/', $filepath );
$file_name = array_pop( $file_name );
@@ -808,7 +830,7 @@ class _Gallery extends Core
/* Image Caption */
if ( !isset( $info['image_caption'] ) )
{
if ( !is_null( $filepath ) )
if ( !\is_null( $filepath ) )
{
$caption = explode( '/', $info['image_file_name'] );
$caption = array_pop( $caption );
@@ -852,7 +874,7 @@ class _Gallery extends Core
/* Okay, let's create our image. We can use data returned from this later if it's missing. */
try
{
if ( is_null( $filedata ) AND !is_null( $filepath ) )
if ( \is_null( $filedata ) AND !\is_null( $filepath ) )
{
if( !file_exists( $filepath ) )
{
@@ -1248,13 +1270,13 @@ class _Gallery extends Core
if ( isset( $info['review_votes_data'] ) )
{
if ( !is_array( $info['review_votes_data'] ) )
if ( !\is_array( $info['review_votes_data'] ) )
{
$info['review_votes_data'] = json_decode( $info['review_votes_data'], TRUE );
}
$newVoters = array();
if ( !is_null( $info['review_votes_data'] ) AND count( $info['review_votes_data'] ) )
if ( !\is_null( $info['review_votes_data'] ) AND \count( $info['review_votes_data'] ) )
{
foreach( $info['review_votes_data'] AS $member => $vote )
{
@@ -1271,7 +1293,7 @@ class _Gallery extends Core
}
}
if ( count( $newVoters ) )
if ( \count( $newVoters ) )
{
$info['review_votes_data'] = json_encode( $newVoters );
}
@@ -1287,19 +1309,19 @@ class _Gallery extends Core
if ( !isset( $info['review_votes'] ) )
{
if ( is_null( $info['review_votes_data'] ) )
if ( \is_null( $info['review_votes_data'] ) )
{
$info['review_votes'] = 0;
}
else
{
$info['review_votes'] = count( json_decode( $info['review_votes_data'], TRUE ) );
$info['review_votes'] = \count( json_decode( $info['review_votes_data'], TRUE ) );
}
}
if ( !isset( $info['review_votes_helpful'] ) )
{
if ( is_null( $info['review_votes_data'] ) )
if ( \is_null( $info['review_votes_data'] ) )
{
$info['review_votes_helpful'] = 0;
}
@@ -1556,13 +1578,13 @@ class _Gallery extends Core
if ( isset( $info['review_votes_data'] ) )
{
if ( !is_array( $info['review_votes_data'] ) )
if ( !\is_array( $info['review_votes_data'] ) )
{
$info['review_votes_data'] = json_decode( $info['review_votes_data'], TRUE );
}
$newVoters = array();
if ( !is_null( $info['review_votes_data'] ) AND count( $info['review_votes_data'] ) )
if ( !\is_null( $info['review_votes_data'] ) AND \count( $info['review_votes_data'] ) )
{
foreach( $info['review_votes_data'] AS $member => $vote )
{
@@ -1579,7 +1601,7 @@ class _Gallery extends Core
}
}
if ( count( $newVoters ) )
if ( \count( $newVoters ) )
{
$info['review_votes_data'] = json_encode( $newVoters );
}
@@ -1595,19 +1617,19 @@ class _Gallery extends Core
if ( !isset( $info['review_votes'] ) )
{
if ( is_null( $info['review_votes_data'] ) )
if ( \is_null( $info['review_votes_data'] ) )
{
$info['review_votes'] = 0;
}
else
{
$info['review_votes'] = count( json_decode( $info['review_votes_data'], TRUE ) );
$info['review_votes'] = \count( json_decode( $info['review_votes_data'], TRUE ) );
}
}
if ( !isset( $info['review_votes_helpful'] ) )
{
if ( is_null( $info['review_votes_data'] ) )
if ( \is_null( $info['review_votes_data'] ) )
{
$info['review_votes_helpful'] = 0;
}
@@ -1647,6 +1669,7 @@ class _Gallery extends Core
* @param array $map Attachment Map Data
* @param string|NULL $filepath The path to the attachment, or NULL.
* @param string|NULL $filedata The binary data of the attachment, or NULL.
* @param string|NULL $thumbnailpath Path to thumbnail, or NULL.
* @return integer|boolean The ID of the newly inserted attachment, or FALSE on failure.
*/
public function convertAttachment( $info=array(), $map=array(), $filepath=NULL, $filedata=NULL, $thumbnailpath = NULL )
@@ -1661,7 +1684,7 @@ class _Gallery extends Core
$info['id3'] = NULL;
}
if ( is_null( $info['id3'] ) OR $info['id3'] != 'review' )
if ( \is_null( $info['id3'] ) OR $info['id3'] != 'review' )
{
$map['id2_type'] = 'gallery_comments';
}
@@ -1694,7 +1717,7 @@ class _Gallery extends Core
*
* @param array $info Data to insert
* @param string|NULL $filepath The path to the image, or NULL.
* @param string|NULL $fileinfo The binary data for the image, or NULL
* @param string|NULL $filedata The binary data for the image, or NULL
* @return integer|boolean The ID of the newly inserted image, or FALSE on failure.
*/
public function convertClubGalleryImage( $info=array(), $filepath=NULL, $filedata=NULL )
+342 -87
View File
@@ -5,19 +5,23 @@
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @since 6 May 2016
*/
namespace IPS\convert\Library;
/* 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;
}
/**
* 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
{
/**
@@ -34,7 +38,7 @@ class _Nexus extends \IPS\convert\Library
public function menuRows( $rowCounts=FALSE )
{
$return = array();
$classname = get_class( $this->software );
$extraRows = $this->software->extraMenuRows();
foreach( $this->getConvertableItems() as $k => $v )
{
@@ -46,7 +50,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusCustomerFields',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customer_fields' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'nexus_customer_fields'
);
@@ -54,7 +58,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';
}
@@ -64,7 +68,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusCustomers',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customers' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => $dependencies,
'link_type' => 'nexus_customers',
);
@@ -76,7 +80,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusCustomerAddresses',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customer_addresses' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers' ),
'link_type' => 'nexus_customer_addresses',
);
@@ -88,7 +92,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusCustomerHistory',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'core_member_history', array( 'log_app=?', 'nexus' ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers' ),
'link_type' => 'nexus_customer_history',
);
@@ -100,7 +104,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusAlternateContacts',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_alternate_contacts' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers' ),
'link_type' => 'nexus_alternate_contacts'
);
@@ -112,11 +116,23 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusNotes',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_notes' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1500,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers' ),
'linK_type' => 'nexus_notes'
);
break;
case 'convertNexusPaymentMethods':
$return[ $k ] = array(
'step_title' => 'convert_nexus_payment_methods',
'step_method' => 'convertNexusPaymentMethods',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_paymethods' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'nexus_payment_methods'
);
break;
case 'convertNexusPackageGroups':
$return[ $k ] = array(
@@ -124,7 +140,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusPackageGroups',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_package_groups' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'nexus_package_groups'
);
@@ -136,7 +152,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusPackageFields',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_package_fields' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'nexus_package_fields'
);
@@ -171,7 +187,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusReviews',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_reviews' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1500,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusPackages' ),
'link_type' => 'nexus_reviews',
'requires_rebuild' => TRUE
@@ -184,7 +200,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusCoupons',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_coupons' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusPackages' ),
'link_type' => 'nexus_coupons'
);
@@ -196,20 +212,31 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusInvoices',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_invoices' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers', 'convertNexusPackages' ),
'link_type' => 'nexus_invoices',
);
break;
case 'convertNexusTransactions':
$dependencies = array();
foreach( array( 'convertNexusCustomers', 'convertNexusInvoices', 'convertNexusPaymentMethods' ) as $dependency )
{
$canConvert = $this->getConvertableItems();
if ( isset( $canConvert[ $dependency ] ) )
{
$dependencies[] = $dependency;
}
}
$return[ $k ] = array(
'step_title' => 'convert_nexus_transactions',
'step_method' => 'convertNexusTransactions',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_transactions' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'dependencies' => array( 'convertNexusCustomers', 'convertNexusInvoices' ),
'per_cycle' => 200,
'dependencies' => $dependencies,
'link_type' => 'nexus_transactions',
);
break;
@@ -220,7 +247,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusPurchases',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers', 'convertNexusPackages', 'convertNexusInvoices' ),
'link_type' => 'nexus_purchases'
);
@@ -232,7 +259,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusFraudRules',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_fraud_rules' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'nexus_fraud_rules',
);
@@ -244,7 +271,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusSupportDepartments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_departments' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusPackages' ),
);
break;
@@ -255,7 +282,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusSupportFields',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_fields' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusSupportDepartments' ),
'link_type' => 'nexus_support_fields',
);
@@ -267,7 +294,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusSupportStatuses',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_statuses' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'nexus_support_statuses',
);
@@ -279,7 +306,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusSupportSeverities',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_severities' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusSupportDepartments' ),
'link_type' => 'nexus_support_severities'
);
@@ -291,7 +318,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusSupportStockActions',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_stock_actions' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusSupportDepartments' ),
'link_type' => 'nexus_support_stock_actions'
);
@@ -303,7 +330,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusSupportRequests',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_requests' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1500,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers', 'convertNexusSupportDepartments', 'convertNexusSupportFields' ),
'link_type' => 'nexus_support_requests',
'requires_rebuild' => TRUE
@@ -316,16 +343,23 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusSupportReplies',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_replies' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusSupportRequests' ),
'link_type' => 'nexus_support_replies',
'requires_rebuild' => TRUE
);
break;
}
}
$return = $this->software->extraMenuRows( $return );
/* Append any extra steps immediately to retain ordering */
if( isset( $v['extra_steps'] ) )
{
foreach( $v['extra_steps'] as $extra )
{
$return[ $extra ] = $extraRows[ $extra ];
}
}
}
/* Run the queries if we want row counts */
if( $rowCounts )
@@ -339,13 +373,13 @@ class _Nexus extends \IPS\convert\Library
/**
* Returns an array of tables that need to be truncated when Empty Local Data is used
*
* @param string The method to truncate.
* @param string $method Method to truncate
* @return array
*/
protected function truncate( $method )
{
$return = array();
$classname = get_class( $this->software );
$classname = \get_class( $this->software );
if( $classname::canConvert() === NULL )
{
@@ -398,7 +432,11 @@ class _Nexus extends \IPS\convert\Library
'nexus_packages_products' => NULL,
);
break;
case 'convertNexusPaymentMethods':
$return['convertNexusPaymentMethods'] = array( 'nexus_paymethods' => NULL );
break;
case 'convertNexusReviews':
$return['convertNexusReviews'] = array( 'nexus_reviews' => NULL );
break;
@@ -473,8 +511,8 @@ class _Nexus extends \IPS\convert\Library
/**
* Convert a customer
*
* @param array Data to insert
* @param array Custom Field Data
* @param array $info Data to insert
* @param array $fields Custom Field Data
* @return int|bool The ID of the inserted customer, or FALSE on failure
*/
public function convertNexusCustomer( $info, $fields=array() )
@@ -516,7 +554,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'] );
}
@@ -537,7 +575,7 @@ class _Nexus extends \IPS\convert\Library
/**
* Format Customer Fields for saving
*
* @param array The fields
* @param array $fields The fields
* @return array Formatted Fields
*/
protected function _formatCustomerFields( $fields )
@@ -545,7 +583,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 );
}
@@ -564,11 +602,66 @@ class _Nexus extends \IPS\convert\Library
return $return;
}
/**
* @brief Allowed currencies
*/
protected $_allowedCurrencies = array( 'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN', 'BAM', 'BBD',
'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BRL', 'BSD', 'BTN', 'BWP', 'BYN', 'BYR', 'BZD', 'CAD', 'CDF', 'CHF',
'CLF', 'CLP', 'CNY', 'COP', 'CRC', 'CUC', 'CUP', 'CVE', 'CZK', 'DJF', 'DKK', 'DOP', 'DZD', 'EGP', 'ERN', 'ETB', 'EUR',
'FJD', 'FKP', 'GBP', 'GEL', 'GGP', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL', 'HRK', 'HTG', 'HUF', 'IDR',
'ILS', 'IMP', 'INR', 'IQD', 'IRR', 'ISK', 'JEP', 'JMD', 'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD',
'KYD', 'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', 'MAD', 'MDL', 'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRO', 'MUR',
'MVR', 'MWK', 'MXN', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR', 'PAB', 'PEN', 'PGK', 'PHP', 'PKR',
'PLN', 'PYG', 'QAR', 'RON', 'RSD', 'RUB', 'RWF', 'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLL', 'SOS', 'SPL*',
'SRD', 'STD', 'SVC', 'SYP', 'SZL', 'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TVD', 'TWD', 'TZS', 'UAH', 'UGX',
'USD', 'UYU', 'UZS', 'VEF', 'VND', 'VUV', 'WST', 'XAF', 'XCD', 'XDR', 'XOF', 'XPF', 'YER', 'ZAR', 'ZMW', 'ZWD' );
/**
* Convert a currency
*
* @param array Info
* @return int|bool The newly inserted currency, or FALSE on failure
*/
public function convertNexusCurrency( $info )
{
if ( !isset( $info['code'] ) )
{
$this->software->app->log( 'nexus_currency_missing_code', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
/* Normalise the currency code */
$info['code'] = \strtoupper( $info['code'] );
if ( !\in_array( $info['code'], $this->_allowedCurrencies ) )
{
$this->software->app->log( 'nexus_currency_not_allowed', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
$currencies = json_decode( \IPS\Settings::i()->nexus_currency, TRUE );
/* Currencies are a little odd in that they don't really have a link */
if( isset( $currencies[ $info['code'] ] ) )
{
return $info['code'];
}
/* Add our currency */
$currencies[ $info['code'] ] = array();
/* save */
\IPS\Settings::i()->changeValues( array( 'nexus_currency' => json_encode( $currencies ) ) );
return $info['code'];
}
/**
* Convert a note
*
* @param array Info
* @param array $info Info
* @return int|bool The newly inserted note ID, or FALSE on failure
*/
public function convertNexusNote( $info )
@@ -650,9 +743,9 @@ class _Nexus extends \IPS\convert\Library
/**
* Convert a package group
*
* @param array Info
* @param string|NULL Path to the groups cover photo, or NULL
* @param string|NULL Raw filedata for the groups cover photo, or NULL
* @param array $info Info
* @param string|NULL $filepath Path to the groups cover photo, or NULL
* @param string|NULL $filedata Raw filedata for the groups cover photo, or NULL
* @return int|bool THe ID of the newly inserted package group, or FALSE on failure
*/
public function convertNexusPackageGroup( $info, $filepath=NULL, $filedata=NULL )
@@ -694,9 +787,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 );
@@ -739,11 +832,74 @@ class _Nexus extends \IPS\convert\Library
}
/**
* Convert a package
* Convert a pay method
*
* @param array $info Info
* @param string $filePath Path to images
* @return int|bool The ID of the newly inserted package, or FALSE on failure
* @return int|bool The ID of the newly inserted payment gateway, or FALSE on failure
*/
public function convertNexusPaymentMethod( $info )
{
/* !Required: ID */
if ( !isset( $info['m_id'] ) )
{
$this->software->app->log( 'nexus_payment_method_missing_id', __METHOD__, \IPS\convert\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'] );
return FALSE;
}
$info['m_gateway'] = $this->_isPaymentMethodSupported( $info['m_gateway'] );
if( $info['m_gateway'] === FALSE )
{
$this->software->app->log( 'nexus_payment_method_not_supported', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['m_id'] );
return FALSE;
}
if ( isset( $info['m_name'] ) )
{
$name = $info['m_name'];
unset( $info['m_name'] );
}
else
{
$name = $info['m_gateway'];
}
$gateway = array(
'm_gateway' => '',
'm_settings' => '{"client_id":"","secret":""}',
'm_active' => 0,
'm_position' => 0,
'm_countries' => '*'
);
$originalId = $info['m_id'];
unset( $info['m_id'], $info['m_name'] );
/* Save Product Data */
$insertedId = \IPS\Db::i()->insert( 'nexus_paymethods', $this->_getValues( $gateway, $info ) );
/* Custom lang strings */
\IPS\Lang::saveCustom( 'nexus', "nexus_paymethod_{$insertedId}", $name );
/* Add Link */
$this->software->app->addLink( $insertedId, $originalId, 'nexus_payment_methods' );
return $insertedId;
}
/**
* Convert a 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 convertNexusPackage( $info, $filePath=NULL )
{
@@ -858,30 +1014,38 @@ class _Nexus extends \IPS\convert\Library
catch( \UnderflowException $e ) { }
}
/* Default Currency */
$currency = \IPS\nexus\Customer::loggedIn()->defaultCurrency();
$price = new \IPS\nexus\Money( $info['p_base_price'], $currency );
$basePrice = [ $currency => [ 'amount' => $price->amount, 'currency' => $currency ] ];
/* Base Price */
array_walk( $info['p_base_price'], function( &$value, $currency )
{
$price = new \IPS\nexus\Money( $value, $currency );
$value = [ 'amount' => $price->amount, 'currency' => $currency ];
});
$basePrice = $info['p_base_price'];
unset( $info['p_base_price'] );
/* Renewal costs & terms */
if( isset( $info['p_renew_options'] ) AND count( $info['p_renew_options'] ) )
$renewals = array();
if( isset( $info['p_renew_options'] ) AND \count( $info['p_renew_options'] ) )
{
$newOptions = array();
foreach( $info['p_renew_options'] as $value )
foreach ( $info['p_renew_options'] as $currency => $options )
{
$price = new \IPS\nexus\Money( $value['price'], $currency );
$renewPrice = [ $currency => [ 'amount' => $price->amount, 'currency' => $currency ] ];
$newOptions[] = array(
'cost' => $renewPrice,
'term' => $value['term'],
'unit' => $value['unit'],
'add' => isset( $value['add'] ) ? $value['add'] : false
$newOptions = array(
'cost' => [],
'term' => $options['term'],
'unit' => $options['unit'],
'add' => isset( $options['add'] ) ? $options['add'] : false
);
foreach ( $options['cost'] as $currency => $cost )
{
$price = new \IPS\nexus\Money( $cost, $currency );
$newOptions['cost'][ $currency ] = [ 'amount' => $price->amount, 'currency' => $currency ];
}
$renewals[] = $newOptions;
}
$info['p_renew_options'] = json_encode( $newOptions );
$info['p_renew_options'] = json_encode( $renewals );
}
/* Discounts */
@@ -953,7 +1117,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 );
@@ -972,9 +1136,9 @@ class _Nexus extends \IPS\convert\Library
}
/* Insert Images */
if( is_array( $images ) AND count( $images ) )
if( \is_array( $images ) AND \count( $images ) )
{
\IPS\Db::insert( 'nexus_package_images', $images );
\IPS\Db::i()->insert( 'nexus_package_images', $images );
}
}
@@ -1004,14 +1168,23 @@ class _Nexus extends \IPS\convert\Library
}
/* Base Price */
if ( !\IPS\Db::i()->checkForColumn( 'nexus_package_base_prices', $currency ) )
$insert = [ 'id' => $insertedId ];
foreach( $basePrice as $currency => $amount )
{
\IPS\Db::i()->addColumn( 'nexus_package_base_prices', array(
'name' => $currency,
'type' => 'FLOAT'
) );
/* check the currency is set up */
$this->convertNexusCurrency( [ 'code' => $currency ] );
/* Check the table */
if ( !\IPS\Db::i()->checkForColumn( 'nexus_package_base_prices', $currency ) )
{
\IPS\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', array( 'id' => $insertedId, $currency => $price->amount ) );
\IPS\Db::i()->insert( 'nexus_package_base_prices', $insert );
/* Custom lang strings */
\IPS\Lang::saveCustom( 'nexus', "nexus_package_{$insertedId}", $name );
@@ -1029,10 +1202,11 @@ class _Nexus extends \IPS\convert\Library
/**
* Convert an invoice
*
* @param array $info Info
* @return int|bool The ID of the newly inserted invoice, or FALSE on failure
* @param array $info Info
* @param string $currency Invoice Currency
* @return int|bool The ID of the newly inserted invoice, or FALSE on failure
*/
public function convertNexusInvoice( $info )
public function convertNexusInvoice( $info, $currency )
{
/* !Required: ID */
if ( !isset( $info['i_id'] ) )
@@ -1041,15 +1215,21 @@ class _Nexus extends \IPS\convert\Library
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 );
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'] );
return FALSE;
}
/* Default Currency */
$currency = \IPS\nexus\Customer::loggedIn()->defaultCurrency();
$price = new \IPS\nexus\Money( $info['i_total'], $currency );
$info['i_total'] = $price->amount;
@@ -1057,9 +1237,20 @@ class _Nexus extends \IPS\convert\Library
$newItems = array();
foreach( $info['i_items'] as $item )
{
$item['itemID'] = $this->software->app->getLink( $item['itemID'], 'nexus_packages' );
$newItems[] = $item;
try
{
$item['itemID'] = $this->software->app->getLink( $item['itemID'], 'nexus_packages' );
$newItems[] = $item;
}
catch( \OutOfRangeException $e ) {}
}
if( !\count( $newItems ) )
{
$this->software->app->log( 'nexus_invoices_missing_mapped_items', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['i_id'] );
return FALSE;
}
$info['i_items'] = json_encode( $newItems );
/* Find member */
@@ -1111,10 +1302,11 @@ class _Nexus extends \IPS\convert\Library
/**
* Convert a transaction
*
* @param array $info Info
* @return int|bool The ID of the newly inserted transaction, or FALSE on failure
* @param array $info Info
* @param string $currency Transaction Currency
* @return int|bool The ID of the newly inserted transaction, or FALSE on failure
*/
public function convertNexusTransaction( $info )
public function convertNexusTransaction( $info, $currency )
{
/* !Required: ID */
if ( !isset( $info['t_id'] ) )
@@ -1144,8 +1336,24 @@ class _Nexus extends \IPS\convert\Library
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 );
return FALSE;
}
/* Map IDs */
$info['t_invoice'] = $this->software->app->getLink( $info['t_invoice'], 'nexus_invoices' );
try
{
$info['t_invoice'] = $this->software->app->getLink( $info['t_invoice'], 'nexus_invoices' );
}
catch( \OutOfRangeException $ex )
{
$this->software->app->log( 'nexus_transactions_missing_invoice', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['t_invoice'] );
return FALSE;
}
try
{
$info['t_member'] = $this->software->app->getLink( $info['t_member'], 'core_members', TRUE );
@@ -1156,8 +1364,20 @@ class _Nexus extends \IPS\convert\Library
return FALSE;
}
/* !Payment Method */
if( isset( $info['t_method'] ) )
{
try
{
$info['t_method'] = $this->software->app->getLink( $info['t_method'], 'nexus_payment_methods' );
}
catch ( \OutOfRangeException $ex )
{
$info['t_method'] = 0;
}
}
/* Default Currency */
$currency = \IPS\nexus\Customer::loggedIn()->defaultCurrency();
$price = new \IPS\nexus\Money( $info['t_amount'], $currency );
$info['t_amount'] = $price->amount;
@@ -1193,9 +1413,10 @@ class _Nexus extends \IPS\convert\Library
* Convert a purchase
*
* @param array $info Info
* @return int|bool The ID of the newly inserted purchase, or FALSE on failure
* @param string $currency Transaction Currency
* @return int|bool The ID of the newly inserted purchase, or FALSE on failure
*/
public function convertNexusPurchase( $info )
public function convertNexusPurchase( $info, $currency )
{
/* !Required: ID */
if ( !isset( $info['ps_id'] ) )
@@ -1218,8 +1439,24 @@ class _Nexus extends \IPS\convert\Library
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 );
return FALSE;
}
/* Map IDs */
$info['ps_original_invoice'] = $this->software->app->getLink( $info['ps_original_invoice'], 'nexus_invoices' );
try
{
$info['ps_original_invoice'] = $this->software->app->getLink( $info['ps_original_invoice'], 'nexus_invoices' );
}
catch( \OutOfRangeException $ex)
{
$this->software->app->log( 'nexus_purchases_missing_invoice', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['ps_id'] );
return FALSE;
}
$info['ps_item_id'] = $this->software->app->getLink( $info['ps_item_id'], 'nexus_packages' );
try
@@ -1264,7 +1501,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 = [];
@@ -1283,7 +1520,6 @@ class _Nexus extends \IPS\convert\Library
$info['ps_extra'] = json_encode( $info['ps_extra'] );
/* Default Currency */
$currency = \IPS\nexus\Customer::loggedIn()->defaultCurrency();
if( isset( $info['ps_renewal_price'] ) )
{
$price = new \IPS\nexus\Money( $info['ps_renewal_price'], $currency );
@@ -1354,4 +1590,23 @@ class _Nexus extends \IPS\convert\Library
return $defaults;
}
/**
* Check whether a given payment method is supported by Commerce
*
* @param $method
* @return bool
*/
protected function _isPaymentMethodSupported( $method )
{
$availableGateways = \IPS\nexus\Gateway::gateways();
$methodKey = array_search( $method, array_keys( array_change_key_case( $availableGateways, CASE_LOWER ) ) );
if( $methodKey !== FALSE )
{
return array_keys( $availableGateways )[ $methodKey ];
}
return FALSE;
}
}