Version 4.0.13.1

This commit is contained in:
Neo committed 2025-12-19 04:57:54 -08:00
1 parent f9e857d255
commit c6a86f0d9b
7517 files changed
+597400 -668041

No files matched your search

Whitespace-only changes.
@@ -0,0 +1,324 @@
<?php
$SQL = array();
/* Clean up from previous versions */
if ( \IPS\Db::i()->checkForTable( 'gallery_albums' ) AND \IPS\Db::i()->checkForTable( 'gallery_albums_main' ) )
{
$SQL[] = "DROP TABLE gallery_albums;";
}
if ( \IPS\Db::i()->checkForTable( 'gallery_albums_temp' ) )
{
$SQL[] = "DROP TABLE gallery_albums_temp;";
}
if ( \IPS\Db::i()->checkForTable( 'gallery_categories' ) )
{
$SQL[] = "DROP TABLE gallery_categories;";
}
if ( \IPS\Db::i()->checkForTable( 'gallery_ecardlog' ) )
{
$SQL[] = "DROP TABLE gallery_ecardlog;";
}
if ( \IPS\Db::i()->checkForTable( 'gallery_favorites' ) )
{
$SQL[] = "DROP TABLE gallery_favorites;";
}
if ( \IPS\Db::i()->checkForTable( 'gallery_subscriptions' ) )
{
$SQL[] = "DROP TABLE gallery_subscriptions;";
}
if ( \IPS\Db::i()->checkForTable( 'gallery_upgrade_history' ) )
{
$SQL[] = "DROP TABLE gallery_upgrade_history;";
}
if ( \IPS\Db::i()->checkForColumn( 'gallery_images', 'category_id' ) )
{
$SQL[] = "ALTER TABLE gallery_images DROP category_id;";
}
/* This old index laying around? */
if( \IPS\Db::i()->checkForIndex( 'gallery_bandwidth', 'date' ) )
{
$SQL[] = "ALTER TABLE gallery_bandwidth DROP INDEX `date`;";
}
/* Old settings potentially still around */
$SQL[] = "DELETE FROM core_sys_conf_settings WHERE conf_key IN ( 'gallery_display_category', 'gallery_display_album', 'gallery_default_view', 'gallery_enable_both_views',
'gallery_full_image', 'gallery_display_block_row', 'gallery_web_accessible', 'gallery_display_photostrip', 'gallery_last_updated', 'gallery_show_lastpic',
'gallery_display_subcats', 'gallery_dir_images', 'gallery_cache_albums', 'gallery_stats_where', 'gallery_images_per_block', 'gallery_last5_images',
'gallery_random_images', 'gallery_stats', 'gallery_feature_image', 'gallery_thumbnail_link', 'gallery_thumb_width', 'gallery_thumb_height', 'gallery_allowed_domains',
'gallery_antileech_image', 'gallery_use_rate', 'gallery_rate_display', 'gallery_bandwidth_thumbs', 'gallery_use_ecards', 'display_hotlinking', 'gallery_guests_ecards',
'gallery_comment_order', 'gallery_allow_usercopyright', 'gallery_copyright_default', 'gallery_exif', 'gallery_iptc', 'gallery_exif_sections', 'gallery_notices_cat',
'gallery_notices_album', 'gallery_notices_img', 'gallery_idx_num_col', 'gallery_idx_num_row', 'gallery_stats_col', 'gallery_stats_row', 'gallery_stats_cols', 'gallery_stats_rows' );";
/* Convert ratings table (easy) */
if ( \IPS\Db::i()->checkForColumn( 'gallery_ratings', 'id' ) )
{
$SQL[] = "ALTER TABLE gallery_ratings CHANGE id rate_id BIGINT NOT NULL AUTO_INCREMENT,
CHANGE member_id rate_member_id INT NOT NULL DEFAULT 0,
CHANGE rating_where rate_type VARCHAR(32) NOT NULL DEFAULT 'image',
CHANGE rating_foreign_id rate_type_id BIGINT NOT NULL DEFAULT 0,
CHANGE rdate rate_date INT NOT NULL DEFAULT 0,
CHANGE rate rate_rate INT NOT NULL DEFAULT 0,
DROP INDEX rating_find_me,
ADD INDEX rating_find_me ( rate_member_id, rate_type, rate_type_id );";
}
/* Convert comments table (easy) - we used to use ignore keyword to prevent warnings about truncating the edit time, but now we need to do this
the long way since alter ignore table has been removed */
if ( \IPS\Db::i()->checkForColumn( 'gallery_comments', 'pid' ) )
{
/* Note that we have to manually set the prefix for some of these because the auto-replacement regex doesn't look for them */
$SQL[] = "CREATE TABLE gallery_comments_temp LIKE " . \IPS\Db::i()->prefix . "gallery_comments;";
$SQL[] = "ALTER TABLE gallery_comments_temp CHANGE pid comment_id INT NOT NULL AUTO_INCREMENT,
CHANGE edit_time comment_edit_time INT NOT NULL DEFAULT 0,
CHANGE author_id comment_author_id INT NOT NULL DEFAULT 0,
CHANGE author_name comment_author_name VARCHAR(255) NULL DEFAULT NULL,
CHANGE ip_address comment_ip_address VARCHAR(46) NULL DEFAULT NULL,
CHANGE post_date comment_post_date INT NOT NULL DEFAULT 0,
CHANGE comment comment_text TEXT NULL DEFAULT NULL,
CHANGE approved comment_approved TINYINT NOT NULL DEFAULT 0,
CHANGE img_id comment_img_id BIGINT NOT NULL DEFAULT 0,
ADD INDEX (comment_ip_address),
DROP INDEX img_id,
ADD INDEX img_id (comment_img_id,comment_post_date);";
$SQL[] = "INSERT IGNORE INTO " . \IPS\Db::i()->prefix . "gallery_comments_temp SELECT * FROM " . \IPS\Db::i()->prefix . "gallery_comments;";
$SQL[] = "DROP TABLE gallery_comments;";
$SQL[] = "RENAME TABLE gallery_comments_temp TO gallery_comments;";
}
if ( \IPS\Db::i()->checkForColumn( 'gallery_comments', 'use_sig' ) )
{
$SQL[] = "ALTER TABLE gallery_comments DROP use_sig;";
}
if ( \IPS\Db::i()->checkForColumn( 'gallery_comments', 'use_emo' ) )
{
$SQL[] = "ALTER TABLE gallery_comments DROP use_emo;";
}
if ( \IPS\Db::i()->checkForColumn( 'gallery_comments', 'edit_name' ) )
{
$SQL[] = "ALTER TABLE gallery_comments DROP edit_name;";
}
if ( \IPS\Db::i()->checkForColumn( 'gallery_comments', 'append_edit' ) )
{
$SQL[] = "ALTER TABLE gallery_comments DROP append_edit;";
}
if ( \IPS\Db::i()->checkForIndex( 'gallery_comments', 'img_id_2' ) )
{
$SQL[] = "ALTER TABLE gallery_comments DROP INDEX img_id_2;";
}
/* Add new column to temp uploads table (easy) */
if ( !\IPS\Db::i()->checkForColumn( 'gallery_images_uploads', 'upload_category_id' ) )
{
$SQL[] = "ALTER TABLE gallery_images_uploads ADD upload_category_id INT NOT NULL DEFAULT 0 AFTER upload_album_id;";
}
/* And then convert images - not too difficult */
if ( \IPS\Db::i()->checkForIndex( 'gallery_images', 'album_id' ) )
{
$SQL[] = "ALTER TABLE gallery_images DROP INDEX album_id;";
}
if ( \IPS\Db::i()->checkForIndex( 'gallery_images', 'approved' ) )
{
$SQL[] = "ALTER TABLE gallery_images DROP INDEX approved;";
}
if ( \IPS\Db::i()->checkForIndex( 'gallery_images', 'album_id_2' ) )
{
$SQL[] = "ALTER TABLE gallery_images DROP INDEX album_id_2;";
}
if ( \IPS\Db::i()->checkForIndex( 'gallery_images', 'gb_select' ) )
{
$SQL[] = "ALTER TABLE gallery_images DROP INDEX gb_select;";
}
if ( \IPS\Db::i()->checkForIndex( 'gallery_images', 'image_feature_flag' ) )
{
$SQL[] = "ALTER TABLE gallery_images DROP INDEX image_feature_flag;";
}
if ( \IPS\Db::i()->checkForIndex( 'gallery_images', 'lastcomment' ) )
{
$SQL[] = "ALTER TABLE gallery_images DROP INDEX lastcomment;";
}
if ( \IPS\Db::i()->checkForIndex( 'gallery_images', 'rnd_lookup' ) )
{
$SQL[] = "ALTER TABLE gallery_images DROP INDEX rnd_lookup;";
}
if ( \IPS\Db::i()->checkForColumn( 'gallery_images', 'id' ) )
{
$SQL[] = "ALTER TABLE gallery_images CHANGE id image_id BIGINT NOT NULL AUTO_INCREMENT,
CHANGE member_id image_member_id INT NOT NULL DEFAULT 0,
ADD image_category_id INT NOT NULL DEFAULT 0 AFTER image_member_id,
CHANGE img_album_id image_album_id BIGINT NOT NULL DEFAULT 0,
CHANGE caption image_caption VARCHAR(255) NOT NULL,
CHANGE description image_description TEXT NULL DEFAULT NULL,
CHANGE directory image_directory VARCHAR(255) NULL DEFAULT NULL,
CHANGE masked_file_name image_masked_file_name VARCHAR(255) NULL DEFAULT NULL,
CHANGE file_name image_file_name VARCHAR(255) NULL DEFAULT NULL,
CHANGE medium_file_name image_medium_file_name VARCHAR(255) NULL DEFAULT NULL,
CHANGE original_file_name image_original_file_name VARCHAR(255) NULL DEFAULT NULL,
CHANGE file_size image_file_size INT NOT NULL DEFAULT 0,
CHANGE file_type image_file_type VARCHAR(50) NULL DEFAULT NULL,
CHANGE approved image_approved TINYINT NOT NULL DEFAULT 0,
CHANGE thumbnail image_thumbnail TINYINT NOT NULL DEFAULT 0,
CHANGE views image_views INT NOT NULL DEFAULT 0,
CHANGE comments image_comments INT NOT NULL DEFAULT 0,
CHANGE comments_queued image_comments_queued INT NOT NULL DEFAULT 0,
CHANGE idate image_date INT NOT NULL DEFAULT 0,
CHANGE ratings_total image_ratings_total INT NOT NULL DEFAULT 0,
CHANGE ratings_count image_ratings_count INT NOT NULL DEFAULT 0,
CHANGE rating image_rating INT NOT NULL DEFAULT 0,
CHANGE lastcomment image_last_comment INT NOT NULL DEFAULT 0,
CHANGE pinned image_pinned TINYINT NOT NULL DEFAULT 0,
CHANGE media image_media TINYINT NOT NULL DEFAULT 0,
CHANGE credit_info image_credit_info TEXT NULL DEFAULT NULL,
CHANGE copyright image_copyright VARCHAR(255) NULL DEFAULT NULL,
CHANGE metadata image_metadata TEXT NULL DEFAULT NULL,
CHANGE media_thumb image_media_thumb VARCHAR(255) NULL DEFAULT NULL,
CHANGE caption_seo image_caption_seo VARCHAR(255) NOT NULL,
CHANGE image_feature_flag image_feature_flag TINYINT NOT NULL DEFAULT 0,
CHANGE image_gps_show image_gps_show TINYINT NOT NULL DEFAULT 0,
ADD INDEX album_id (image_album_id, image_approved, image_date),
ADD INDEX image_feature_flag (image_feature_flag, image_date),
ADD INDEX gb_select (image_approved, image_parent_permission, image_date),
ADD INDEX lastcomment (image_last_comment, image_date);";
}
/* Add our new tables */
$SQL[] = "CREATE TABLE gallery_categories (
category_id int(11) NOT NULL AUTO_INCREMENT,
category_parent_id int(11) NOT NULL DEFAULT '0',
category_name varchar(255) DEFAULT NULL,
category_name_seo varchar(255) DEFAULT NULL,
category_description text,
category_count_imgs int(11) NOT NULL DEFAULT '0',
category_count_comments int(11) NOT NULL DEFAULT '0',
category_count_imgs_hidden int(11) NOT NULL DEFAULT '0',
category_count_comments_hidden int(11) NOT NULL DEFAULT '0',
category_cover_img_id bigint(20) NOT NULL DEFAULT '0',
category_last_img_id bigint(20) NOT NULL DEFAULT '0',
category_last_img_date int(11) NOT NULL DEFAULT '0',
category_type int(11) NOT NULL DEFAULT '0',
category_sort_options text,
category_allow_comments tinyint(4) NOT NULL DEFAULT '0',
category_allow_rating tinyint(4) NOT NULL DEFAULT '0',
category_approve_img tinyint(4) NOT NULL DEFAULT '0',
category_approve_com tinyint(4) NOT NULL DEFAULT '0',
category_rules mediumtext,
category_rating_aggregate int(11) NOT NULL DEFAULT '0',
category_rating_count int(11) NOT NULL DEFAULT '0',
category_rating_total int(11) NOT NULL DEFAULT '0',
category_after_forum_id int(11) NOT NULL DEFAULT '0',
category_watermark tinyint(4) NOT NULL DEFAULT '0',
category_position int(11) NOT NULL DEFAULT '0',
category_can_tag tinyint(4) NOT NULL DEFAULT '0',
category_preset_tags text,
category_public_albums int(11) NOT NULL DEFAULT '0',
category_nonpublic_albums int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (category_id),
KEY category_last_img_id (category_last_img_id)
);";
if( !\IPS\Db::i()->checkForTable( 'gallery_moderators' ) )
{
$SQL[] = "CREATE TABLE gallery_moderators (
mod_id int(11) NOT NULL AUTO_INCREMENT,
mod_type varchar(32) NOT NULL DEFAULT 'group',
mod_type_id int(11) NOT NULL DEFAULT '0',
mod_type_name varchar(255) DEFAULT NULL,
mod_categories text,
mod_can_approve tinyint(4) NOT NULL DEFAULT '0',
mod_can_edit tinyint(4) NOT NULL DEFAULT '0',
mod_can_hide tinyint(4) NOT NULL DEFAULT '0',
mod_can_delete tinyint(4) NOT NULL DEFAULT '0',
mod_can_approve_comments tinyint(4) NOT NULL DEFAULT '0',
mod_can_edit_comments tinyint(4) NOT NULL DEFAULT '0',
mod_can_delete_comments tinyint(4) NOT NULL DEFAULT '0',
mod_can_move tinyint(4) NOT NULL DEFAULT '0',
mod_set_cover_image tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (mod_id),
KEY mod_type (mod_type,mod_type_id)
);";
}
/* Groups table changes? */
if ( \IPS\Db::i()->checkForColumn( 'core_groups', 'g_ecard' ) )
{
$SQL[] = "ALTER TABLE core_groups DROP g_ecard;";
}
if ( \IPS\Db::i()->checkForColumn( 'core_groups', 'g_rate' ) )
{
$SQL[] = "ALTER TABLE core_groups DROP g_rate;";
}
if ( \IPS\Db::i()->checkForColumn( 'core_groups', 'g_slideshows' ) )
{
$SQL[] = "ALTER TABLE core_groups DROP g_slideshows;";
}
if ( \IPS\Db::i()->checkForColumn( 'core_groups', 'g_favorites' ) )
{
$SQL[] = "ALTER TABLE core_groups DROP g_favorites;";
}
if ( \IPS\Db::i()->checkForColumn( 'core_groups', 'g_comment' ) )
{
$SQL[] = "ALTER TABLE core_groups DROP g_comment;";
}
if ( \IPS\Db::i()->checkForColumn( 'core_groups', 'g_move_own' ) )
{
$SQL[] = "ALTER TABLE core_groups DROP g_move_own;";
}
if ( \IPS\Db::i()->checkForColumn( 'core_groups', 'g_mod_albums' ) )
{
$SQL[] = "ALTER TABLE core_groups DROP g_mod_albums;";
}
if ( \IPS\Db::i()->checkForColumn( 'core_groups', 'g_album_private' ) )
{
$SQL[] = "ALTER TABLE core_groups DROP g_album_private;";
}
if ( \IPS\Db::i()->checkForColumn( 'core_groups', 'g_gal_avatar' ) )
{
$SQL[] = "ALTER TABLE core_groups DROP g_gal_avatar;";
}
if ( \IPS\Db::i()->checkForColumn( 'core_groups', 'g_max_notes' ) )
{
$SQL[] = "ALTER TABLE core_groups DROP g_max_notes;";
}
if ( \IPS\Db::i()->checkForColumn( 'core_groups', 'g_gallery_cat_cover' ) )
{
$SQL[] = "ALTER TABLE core_groups DROP g_gallery_cat_cover;";
}
if ( !\IPS\Db::i()->checkForColumn( 'core_groups', 'g_create_albums_private' ) )
{
$SQL[] = "ALTER TABLE core_groups ADD g_create_albums_private TINYINT( 1 ) UNSIGNED default '0' NOT NULL,
ADD g_create_albums_fo TINYINT( 1 ) UNSIGNED default '0' NOT NULL,
ADD g_delete_own_albums TINYINT( 1 ) NOT NULL DEFAULT '0';";
}
/* Albums handled by the upgrader script */
@@ -0,0 +1,536 @@
<?php
/**
* @brief 4.0.0 Upgrade Code
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Gallery
* @since 24 Oct 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\gallery\setup\upg_50000;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* 4.0.0 Upgrade Code
*/
class _Upgrade
{
/**
* Conversion from 3.0
*
* @return array If returns TRUE, upgrader will proceed to next step. If it returns any other value, it will set this as the value of the 'extra' GET parameter and rerun this step (useful for loops)
*/
public function step1()
{
\IPS\core\Setup\Upgrade::runLegacySql( 'gallery', 50000 );
return TRUE;
}
/**
* Convert members album amd categories
*
* @return array If returns TRUE, upgrader will proceed to next step. If it returns any other value, it will set this as the value of the 'extra' GET parameter and rerun this step (useful for loops)
*/
public function step2()
{
if ( !\IPS\Db::i()->checkForColumn( 'gallery_albums_main', 'album_category_id' ) )
{
\IPS\Db::i()->addColumn( 'gallery_albums_main', array( "name" => "album_category_id", "type" => "int", "length" => 40, "allow_null" => false, "default" => '0', "comment" => "", "auto_increment" => false, "binary" => false ) );
}
try
{
$setting = \IPS\Db::i()->select( '*', 'core_sys_conf_settings', array( 'conf_key=?', 'gallery_members_album' ) )->first();
}
catch( \UnderflowException $e )
{
$setting = array(
'conf_key' => 'gallery_members_album',
'conf_value' => 0,
'conf_default' => 0
);
\IPS\Db::i()->insert( 'core_sys_conf_settings', $setting );
\IPS\Settings::i()->gallery_members_album = 0;
}
unset( \IPS\Data\Store::i()->settings );
//-----------------------------------------
// Get global albums and loop
//-----------------------------------------
$albumCatMap = array();
$imagesOnly = array();
$position = 1;
$options = null;
foreach( \IPS\Db::i()->select( '*', 'gallery_albums_main', "album_is_global=1", 'album_position ASC' ) as $album )
{
//-----------------------------------------
// Fix older sort options
//-----------------------------------------
$options = @unserialize( $album['album_sort_options'] );
if( $options['key'] )
{
$options['key'] = ( $options['key'] == 'name' ) ? 'image_caption' : ( ( $options['key'] == 'idate' ) ? 'image_date' : ( ( $options['key'] == 'rating' ) ? 'image_rating' : ( ( $options['key'] == 'comments' ) ? 'image_comments' : ( ( $options['key'] == 'views' ) ? 'image_views' : $options['key'] ) ) ) );
$album['album_sort_options'] = serialize($options);
}
$options = null;
//-----------------------------------------
// Insert new category
//-----------------------------------------
$category = array(
'category_name' => $album['album_name'],
'category_name_seo' => $album['album_name_seo'],
'category_description' => $album['album_description'],
'category_cover_img_id' => $album['album_cover_img_id'],
'category_type' => ( $album['album_g_container_only'] == 1 ) ? 1 : 2,
'category_sort_options' => $album['album_sort_options'],
'category_allow_comments' => $album['album_allow_comments'],
'category_allow_rating' => $album['album_allow_rating'],
'category_approve_img' => $album['album_g_approve_img'],
'category_approve_com' => $album['album_g_approve_com'],
'category_rules' => $album['album_g_rules'],
'category_after_forum_id' => $album['album_after_forum_id'],
'category_watermark' => ( !$album['album_watermark'] ) ? 0 : ( ( $album['album_watermark'] == 2 ) ? 2 : 1 ),
'category_can_tag' => $album['album_can_tag'],
'category_preset_tags' => $album['album_preset_tags'],
'category_position' => $position,
);
$category['category_id'] = \IPS\Db::i()->insert( 'gallery_categories', $category );
if( $album['album_g_perms_thumbs'] == 'member' )
{
\IPS\Settings::i()->gallery_members_album = $category['category_id'];
}
//-----------------------------------------
// Insert permissions
//-----------------------------------------
$permissions = array(
'app' => 'gallery',
'perm_type' => 'categories',
'perm_type_id' => $category['category_id'],
'perm_view' => $album['album_g_perms_view'] ?: '',
'perm_2' => $album['album_g_perms_images'],
'perm_3' => $album['album_g_perms_comments'],
'perm_4' => $album['album_g_perms_comments'],
'perm_5' => $album['album_g_perms_moderate'],
);
\IPS\Db::i()->insert( 'core_permission_index', $permissions );
//-----------------------------------------
// Update images in this category
//-----------------------------------------
\IPS\Db::i()->update( 'gallery_images', array( 'image_category_id' => $category['category_id'], 'image_album_id' => 0, 'image_parent_permission' => $album['album_g_perms_view'], 'image_privacy' => 0 ), 'image_album_id=' . $album['album_id'] );
//-----------------------------------------
// Store mapping
//-----------------------------------------
$position++;
$albumCatMap[ $album['album_id'] ] = array( 'album' => $album, 'category' => $category );
if( $category['category_type'] == 2 )
{
$imagesOnly[] = $category['category_id'];
}
}
//-----------------------------------------
// Fix album data
//-----------------------------------------
$foundMembersGallery = 0;
foreach( $albumCatMap as $albumId => $data )
{
//-----------------------------------------
// Set subcategory parent association if necessary
//-----------------------------------------
if( $data['album']['album_parent_id'] )
{
\IPS\Db::i()->update( 'gallery_categories', array( 'category_parent_id' => $albumCatMap[ $data['album']['album_parent_id'] ]['category']['category_id'] ), 'category_id=' . $data['category']['category_id'] );
}
//-----------------------------------------
// Move our child albums
//-----------------------------------------
\IPS\Db::i()->update( 'gallery_albums_main', array( 'album_category_id' => $data['category']['category_id'], 'album_parent_id' => 0 ), 'album_parent_id=' . $albumId );
//-----------------------------------------
// Fix members album cat association
//-----------------------------------------
if( $albumId == \IPS\Settings::i()->gallery_members_album )
{
\IPS\Settings::i()->gallery_members_album = $data['category']['category_id'];
$foundMembersGallery = $data['category']['category_id'];
\IPS\Db::i()->update( 'gallery_categories', array( 'category_type' => 1 ), 'category_id=' . $data['category']['category_id'] );
}
}
//-----------------------------------------
// If we didn't find a members gallery, make one
//-----------------------------------------
if( !$foundMembersGallery )
{
$category = array(
'category_name' => 'Temp global album for root member albums',
'category_name_seo' => 'temp-global-album-for-root-member-albums',
'category_description' => "This is a temporary global album that holds the member albums that didn't have the proper parent album set. This album has NO permissions and is not visible from the public side, please move the albums in the proper location.",
'category_cover_img_id' => 0,
'category_type' => 1,
'category_sort_options' => '',
'category_allow_comments' => 1,
'category_allow_rating' => 1,
'category_approve_img' => 0,
'category_approve_com' => 0,
'category_rules' => '',
'category_after_forum_id' => 0,
'category_watermark' => 0,
'category_can_tag' => 1,
'category_preset_tags' => '',
'category_position' => $position,
);
$category['category_id'] = \IPS\Db::i()->insert( 'gallery_categories', $category );
$foundMembersGallery = $category['category_id'];
\IPS\Settings::i()->gallery_members_album = $category['category_id'];
}
//-----------------------------------------
// Move any albums in a category with type 2 to members album cat
//-----------------------------------------
if( count( $imagesOnly ) )
{
\IPS\Db::i()->update( 'gallery_albums_main', array( 'album_category_id' => $foundMembersGallery ), 'album_category_id IN(' . implode( ',', $imagesOnly ) . ')' );
}
//-----------------------------------------
// Delete global albums
//-----------------------------------------
\IPS\Db::i()->delete( 'gallery_albums_main', 'album_is_global=1' );
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => \IPS\Settings::i()->gallery_members_album ), array( 'conf_key=?', 'gallery_members_album' ) );
unset( \IPS\Data\Store::i()->settings );
return TRUE;
}
/**
* Clean up missing and extraneous fields and indexes
*
* @return array If returns TRUE, upgrader will proceed to next step. If it returns any other value, it will set this as the value of the 'extra' GET parameter and rerun this step (useful for loops)
*/
public function step3()
{
//-----------------------------------------
// No idea why, but sometimes this index disappears?
// @link http://community.invisionpower.com/resources/bugs.html/_/ip-gallery/missing-index-img-id-after-upgrade-r38838
//-----------------------------------------
if( !\IPS\Db::i()->checkForIndex( 'gallery_comments', 'img_id' ) )
{
if( \IPS\Db::i()->checkForIndex( 'gallery_comments', 'comment_img_id' ) )
{
\IPS\Db::i()->dropIndex( 'gallery_comments', 'comment_img_id' );
}
\IPS\Db::i()->addIndex( 'gallery_comments', array(
'type' => 'index',
'name' => 'img_id',
'columns' => array( 'comment_img_id', 'comment_post_date' )
) );
}
//-----------------------------------------
// Add new columns
//-----------------------------------------
\IPS\Db::i()->addColumn( 'gallery_albums_main', array( "name" => "album_type", "type" => "INT", "length" => 10, "allow_null" => false, "default" => 0, "comment" => "", "auto_increment" => false, "binary" => false ) );
\IPS\Db::i()->addColumn( 'gallery_albums_main', array( "name" => "album_last_x_images", "type" => "TEXT", "length" => null, "allow_null" => true, "default" => null, "comment" => "", "auto_increment" => false, "binary" => false ) );
//-----------------------------------------
// Change existing columns
//-----------------------------------------
\IPS\Db::i()->changeColumn( 'gallery_albums_main', "album_allow_comments", array( "name" => "album_allow_comments", "type" => "TINYINT", "length" => 1, "allow_null" => false, "default" => 0, "comment" => "", "auto_increment" => false, "binary" => false ) );
\IPS\Db::i()->changeColumn( 'gallery_albums_main', "album_allow_rating", array( "name" => "album_allow_rating", "type" => "TINYINT", "length" => 1, "allow_null" => false, "default" => 0, "comment" => "", "auto_increment" => false, "binary" => false ) );
\IPS\Db::i()->changeColumn( 'gallery_albums_main', "album_watermark", array( "name" => "album_watermark", "type" => "TINYINT", "length" => 1, "allow_null" => false, "default" => 0, "comment" => "", "auto_increment" => false, "binary" => false ) );
//-----------------------------------------
// Delete old columns
//-----------------------------------------
\IPS\Db::i()->dropColumn( 'gallery_albums_main', array(
'album_is_global', 'album_is_profile', 'album_cache', 'album_node_level', 'album_node_left', 'album_preset_tags',
'album_node_right', 'album_g_approve_img', 'album_g_approve_com', 'album_g_bitwise', 'album_g_rules',
'album_g_container_only', 'album_g_perms_thumbs', 'album_g_perms_view', 'album_g_perms_images', 'album_g_perms_comments',
'album_g_perms_moderate', 'album_g_latest_imgs', 'album_detail_default', 'album_child_tree', 'album_parent_tree', 'album_can_tag'
) );
return TRUE;
}
/**
* Convert albums step 1
*
* @return array If returns TRUE, upgrader will proceed to next step. If it returns any other value, it will set this as the value of the 'extra' GET parameter and rerun this step (useful for loops)
*/
public function step4()
{
$perCycle = 100;
$did = 0;
$limit = intval( \IPS\Request::i()->extra );
//-----------------------------------------
// Fetch albums that have a parent defined
//-----------------------------------------
foreach( \IPS\Db::i()->select( '*', 'gallery_albums_main', NULL, 'album_id ASC', array( $limit, $percycle ) ) as $row )
{
$did++;
$update = array();
//-----------------------------------------
// Reset watermark
//-----------------------------------------
if( $row['album_watermark'] )
{
$update['album_watermark'] = 1;
}
//-----------------------------------------
// Reset public/private/friend-only
//-----------------------------------------
if( $row['album_is_public'] == 1 )
{
$update['album_type'] = 1;
}
else if( $row['album_is_public'] == 2 )
{
$update['album_type'] = 3;
}
else
{
$update['album_type'] = 2;
}
//-----------------------------------------
// Get the parent (up to 4 levels deep..)
//-----------------------------------------
if( $row['album_parent_id'] )
{
try
{
$parent = \IPS\Db::i()->select( 'album_id, album_parent_id, album_category_id', 'gallery_albums_main', 'album_id=' . intval($row['album_parent_id']) )->first();
}
catch( \UnderflowException $e )
{
$parent = array( 'album_id' => 0 );
}
if( $parent['album_id'] )
{
if( $parent['album_category_id'] )
{
$update['album_category_id'] = $parent['album_category_id'];
}
else if( $parent['album_parent_id'] )
{
try
{
$_parent = \IPS\Db::i()->select( 'album_id, album_parent_id, album_category_id', 'gallery_albums_main', 'album_id=' . intval($parent['album_parent_id']) )->first();
}
catch( \UnderflowException $e )
{
$_parent = array( 'album_id' => 0 );
}
if( $_parent['album_id'] )
{
if( $_parent['album_category_id'] )
{
$update['album_category_id'] = $_parent['album_category_id'];
}
else if( $_parent['album_parent_id'] )
{
try
{
$__parent = \IPS\Db::i()->select( 'album_id, album_parent_id, album_category_id', 'gallery_albums_main', 'album_id=' . intval($_parent['album_parent_id']) )->first();
}
catch( \UnderflowException $e )
{
$__parent = array( 'album_id' => 0 );
}
if( $__parent['album_id'] )
{
if( $__parent['album_category_id'] )
{
$update['album_category_id'] = $__parent['album_category_id'];
}
else if( $__parent['album_parent_id'] )
{
try
{
$___parent = \IPS\Db::i()->select( 'album_id, album_parent_id, album_category_id', 'gallery_albums_main', 'album_id=' . intval($__parent['album_parent_id']) )->first();
}
catch( \UnderflowException $e )
{
$___parent = array( 'album_id' => 0 );
}
if( $___parent['album_category_id'] )
{
$update['album_category_id'] = $___parent['album_category_id'];
}
}
}
}
}
}
}
}
//-----------------------------------------
// If we didn't find cat, move to members albums cat
//-----------------------------------------
if( !$update['album_category_id'] )
{
$update['album_category_id'] = $row['album_category_id'] ? $row['album_category_id'] : (int) \IPS\Settings::i()->gallery_members_album;
}
//-----------------------------------------
// Save updates
//-----------------------------------------
if( count($update) )
{
\IPS\Db::i()->update( 'gallery_albums_main', $update, 'album_id=' . $row['album_id'] );
}
}
//-----------------------------------------
// Got any more? .. redirect
//-----------------------------------------
if( $did )
{
return ( $limit + $did );
}
else
{
return TRUE;
}
}
/**
* Convert albums step 2
*
* @return array If returns TRUE, upgrader will proceed to next step. If it returns any other value, it will set this as the value of the 'extra' GET parameter and rerun this step (useful for loops)
*/
public function step5()
{
//-----------------------------------------
// Move any lingering albums to member album cat
//-----------------------------------------
\IPS\Db::i()->update( 'gallery_albums_main', array( 'album_category_id' => (int) \IPS\Settings::i()->gallery_members_album ), 'album_category_id=0' );
//-----------------------------------------
// Delete old columns
//-----------------------------------------
\IPS\Db::i()->dropColumn( 'gallery_albums_main', 'album_parent_id' );
\IPS\Db::i()->dropColumn( 'gallery_albums_main', 'album_is_public' );
//-----------------------------------------
// Update indexes
//-----------------------------------------
if( \IPS\Db::i()->checkForIndex( 'gallery_albums_main', 'album_nodes' ) )
{
\IPS\Db::i()->dropIndex( 'gallery_albums_main', 'album_nodes' );
}
if( \IPS\Db::i()->checkForIndex( 'gallery_albums_main', 'album_parent_id' ) )
{
\IPS\Db::i()->dropIndex( 'gallery_albums_main', 'album_parent_id' );
}
if( \IPS\Db::i()->checkForIndex( 'gallery_albums_main', 'album_owner_id' ) )
{
\IPS\Db::i()->dropIndex( 'gallery_albums_main', 'album_owner_id' );
}
if( \IPS\Db::i()->checkForIndex( 'gallery_albums_main', 'album_count_imgs' ) )
{
\IPS\Db::i()->dropIndex( 'gallery_albums_main', 'album_count_imgs' );
}
if( \IPS\Db::i()->checkForIndex( 'gallery_albums_main', 'album_has_a_perm' ) )
{
\IPS\Db::i()->dropIndex( 'gallery_albums_main', 'album_has_a_perm' );
}
if( \IPS\Db::i()->checkForIndex( 'gallery_albums_main', 'album_child_lup' ) )
{
\IPS\Db::i()->dropIndex( 'gallery_albums_main', 'album_child_lup' );
}
\IPS\Db::i()->addIndex( 'gallery_albums_main', array(
'type' => 'index',
'name' => 'album_owner_id',
'columns' => array( 'album_owner_id', 'album_last_img_date' )
) );
\IPS\Db::i()->addIndex( 'gallery_albums_main', array(
'type' => 'index',
'name' => 'album_parent_id',
'columns' => array( 'album_category_id', 'album_name_seo' )
) );
//-----------------------------------------
// Rename the table
//-----------------------------------------
\IPS\Db::i()->renameTable( 'gallery_albums_main', 'gallery_albums' );
return TRUE;
}
}