View Issue Details

IDProjectCategoryView StatusLast Update
0004569Composr non-bundled addons[All Projects] General / Uncategorisedpublic2021-01-27 02:05
ReporterChris GrahamAssigned To 
SeverityFeature-request 
Status non-assignedResolutionopen 
Summary0004569: Script to transition IOTDs to galleries
DescriptionIn v11 the iotds addon will be no longer available, at least officially. It's recommended people move to galleries and just randomise a gallery image.

Create some migration script. Below is one I wrote for a client people could repurpose. It makes assumptions, esp that content translation is disabled.
Additional Informationrequire_code('galleries2');
$test = $GLOBALS['SITE_DB']->query_select_value_if_there('galleries', 'name', array('name' => 'iotds'));
if ($test === null) {
    add_gallery('iotds', 'Images of the day', 'Images of the day (prior to ' . date('Y/m/d') . ' upgrade).', '', 'root');
}

$forum = get_option('comments_forum_name');

$max = 10;
$start = 0;
do {
    $iotds = $GLOBALS['SITE_DB']->query_select('iotd', array('*'), array(), 'ORDER BY id', $max, $start);
    foreach ($iotds as $iotd) {
        $url = $iotd['url'];
        $thumb_url = $iotd['thumb_url'];
        foreach (array(&$url, &$thumb_url) as &$_url) {
            if (preg_match('#^uploads/iotds(_addon)?/#', $_url) != 0) {
                $old_path = get_custom_file_base() . '/' . urldecode($_url);
                $i = 0;
                do {
                    $_url = preg_replace('#[\d_]*(\.\w+)$#', (($i == 0) ? '' : ('_' . strval($i))) . '$1', $_url);
                    $new_path = get_custom_file_base() . '/' . urldecode(preg_replace('#^uploads/iotds(_addon)?/#', 'uploads/galleries/', $_url));
                    $i++;
                } while (file_exists($new_path));
                rename($old_path, $new_path);
            }
        }

        $insert_map = array(
            'cat' => 'iotds',
            'url' => $url,
            'thumb_url' => $thumb_url,
            'allow_rating' => $iotd['allow_rating'],
            'allow_comments' => $iotd['allow_comments'],
            'allow_trackbacks' => $iotd['allow_trackbacks'],
            'notes' => $iotd['notes'],
            'submitter' => $iotd['submitter'],
            'validated' => 1,
            'add_date' => $iotd['add_date'],
            'edit_date' => $iotd['edit_date'],
            'image_views' => $iotd['iotd_views'],
            'description' => $iotd['caption'],
            'title' => $iotd['i_title'],
        );
        if (!multi_lang_content()) {
            $insert_map += array(
                'description__text_parsed' => $iotd['caption__text_parsed'],
                'description__source_user' => $iotd['caption__source_user'],
            );
        }
        $id = $GLOBALS['SITE_DB']->query_insert('images', $insert_map, true);

        if (get_forum_type() == 'cns') {
            $topic_id = $GLOBALS['FORUM_DRIVER']->find_topic_id_for_topic_identifier($forum, 'iotds_' . strval($iotd['id']), do_lang('COMMENT'));
            if ($topic_id !== null) {
                $new_description = do_lang('COMMENT') . ': #iotds_' . strval($iotd['id']);
                $GLOBALS['FORUM_DB']->query_update('f_topics', array('t_description' => $new_description), array('id' => $topic_id), '', 1);
            }
        }
    }
    $start += $max;
} while (!empty($iotds));

$GLOBALS['SITE_DB']->query_delete('iotd');
TagsNo tags attached.
Time estimation (hours)1.5
Sponsorship open

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2021-01-27 02:05 Chris Graham New Issue
2023-02-26 18:29 Chris Graham Category General => General / Uncategorised