/** * Standard import function. * * @param object The DB connection to import from * @param string The table prefix the target prefix is using * @param PATH The base directory we are importing from * @return tempcode Import message */ function import_downloads_and_categories($db, $table_prefix, $old_base_dir) { require_code('downloads2'); require_code('authors'); //check is the comment forum configured in ocPortal $this->test_for_comments_forum(); $category_id_remap = array(); $rows = $db->query('SELECT * FROM ' . $table_prefix . 'download_sections ORDER BY id'); ocf_over_msn(); //used to fixed the correct forum prefix $category_id_remap[0] = db_get_first_id(); ocf_over_local(); //used to fixed the correct forum prefix // Create categories $orig_parents = array(); foreach ($rows as $row) { $id = import_id_remap_get('download_category', strval($row['id']), true); if (!is_null($id)) { $category_id_remap[$row['id']] = $id; continue; } $orig_parents[$row['id']] = array($row['father'], $row['evento'], $row['descrizione']); $id = add_download_category(html_entity_decode($row['evento'], ENT_QUOTES, get_charset()), db_get_first_id(), '', '', ''); $category_id_remap[$row['id']] = $id; ocf_over_msn(); //used to fixed the correct forum prefix $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true); ocf_over_local(); //used to fixed the correct forum prefix foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'downloads', 'category_name' => strval($id), 'group_id' => $group_id)); } import_id_remap_put('download_category', strval($row['id']), $id); } foreach ($orig_parents as $cid => $bits) { list($orig_parent, $category, $description) = $bits; if ($orig_parent == 0) { ocf_over_msn(); //used to fixed the correct forum prefix $parent_id = db_get_first_id(); ocf_over_local(); //used to fixed the correct forum prefix } else { $parent_id = $category_id_remap[$orig_parent]; } ocf_over_msn(); //used to fixed the correct forum prefix edit_download_category(html_entity_decode($category, ENT_QUOTES, get_charset()), $parent_id, html_to_comcode($description), $category_id_remap[$cid], '', '', '', ''); ocf_over_local(); //used to fixed the correct forum prefix } // Read in downloads $rows = $db->query('SELECT * FROM ' . $table_prefix . 'download'); $rows2 = array(); foreach ($rows as $i => $row) { $rows[$i]['validated'] = $row['validate']; $rows[$i]['date'] = $row['data']; $rows2[$i]['totalvotes'] = $row['rate']; $rows2[$i]['hits'] = $row['click']; $rows2[$i]['screenshot'] = $row['screen1']; $rows2[$i]['screenshot2'] = $row['screen2']; } // Import downloads foreach ($rows as $row) { if (import_check_if_imported('download', strval($row['id']))) { continue; } $original_filename = $row['file']; $file_parts = explode('.', $row['file']); $file_ext = count($file_parts) > 1 ? $file_parts[count($file_parts) - 1] : ''; $just_filename = strlen($file_ext) > 0 ? preg_replace('#\\.' . $file_ext . '#', '', $row['file']) : $row['file']; $mkp_disk_name = 'mk_' . strval($row['id']) . '_' . $just_filename . '.mk'; $save_filename = $old_base_dir . '/mkportal/modules/downloads/file/' . $mkp_disk_name; $copy_destination = get_custom_file_base() . '/uploads/downloads/' . $mkp_disk_name; if (@copy($save_filename, $copy_destination) !== false) { fix_permissions($copy_destination); sync_file($copy_destination); } $url = 'uploads/downloads/' . $mkp_disk_name; $comments_text = $row['demo'] == '' ? '' : do_lang('DEMO_URL') . ': ' . $row['demo']; $member = $row['idauth']; if (is_null($member)) { $member = get_member(); } $row['name'] = @html_entity_decode($row['name'], ENT_QUOTES, get_charset()); ocf_over_msn(); //used to fixed the correct forum prefix $new_id = add_download($category_id_remap[$row['idcategoria']], $row['name'], $url, html_to_comcode($row['description']), $row['autore'], html_to_comcode($comments_text), NULL, $row['validate'], 1, 1, 1, '', $original_filename, $row['peso'], 0, 0, NULL, $row['data'], $row['downloads'], $row['click'], $member); ocf_over_local(); //used to fixed the correct forum prefix import_id_remap_put('download', strval($row['id']), $new_id); //get comments forum $forum_name = get_option('comments_forum_name'); ocf_over_msn(); //used to fixed the correct forum prefix $forum_id = $GLOBALS['FORUM_DRIVER']->forum_id_from_name($forum_name); ocf_over_local(); //used to fixed the correct forum prefix // Comments $comments = $db->query('SELECT * FROM ' . $table_prefix . 'download_comments WHERE identry=' . strval($row['id']) . ' ORDER BY data'); if (!is_null($forum_id)) { foreach ($comments as $comment) { ocf_over_msn(); //used to fixed the correct forum prefix $member = $GLOBALS['FORUM_DRIVER']->get_member_from_username($comment['autore']); if (is_null($member)) { $member = $GLOBALS['FORUM_DRIVER']->get_guest_id(); } ocf_over_local(); //used to fixed the correct forum prefix $title = ''; $post = $comment['testo']; $content_url = build_url(array('page' => 'downloads', 'id' => $new_id, 'type' => 'view'), get_module_zone('downloads')); ocf_over_msn(); //used to fixed the correct forum prefix $GLOBALS['FORUM_DRIVER']->make_post_forum_topic($forum_name, 'downloads_' . strval($new_id), $member, $title, html_to_comcode($post), $row['name'], do_lang('COMMENT'), $content_url->evaluate()); ocf_over_local(); //used to fixed the correct forum prefix } } //check is the 'galleries' addon installed first, before importing the screenshots if (addon_installed('galleries')) { // Image if ($row['screen1'] != '') { $image_url = $row['screen1']; $thumb_url = ''; add_image('', 'download_' . strval($new_id), '', $image_url, $thumb_url, $row['validate'], 1, 1, 1, ''); } // Image 2 if ($row['screen2'] != '') { $image_url = $row['screen2']; $thumb_url = ''; add_image('', 'download_' . strval($new_id), '', $image_url, $thumb_url, $row['validate'], 1, 1, 1, ''); } } //import download rating too $this->_import_ratings($db, 'downloads', $row['id'], $new_id, $row['rate'], $table_prefix); } $out = do_template('IMPORT_MESSAGE', array('_GUID' => 'ff9131c37b9e4fa2cff991e3479ae867', 'MESSAGE' => do_lang_tempcode('IMPORT_REBUILD_CACHE', do_lang('IMAGE_THUMBNAILS')))); return $out; }
function testEditDownloads_category() { edit_download_category('test', 1, 'test', $this->dwn_cat_id, 'edit_test', '', '', ''); $this->assertTrue('edit_test' == $GLOBALS['SITE_DB']->query_value('download_categories', 'notes', array('id' => $this->dwn_cat_id))); }
/** * Standard import function. * * @param object The DB connection to import from * @param string The table prefix the target prefix is using * @param PATH The base directory we are importing from * @return tempcode Import message */ function import_downloads_and_categories($db, $table_prefix, $old_base_dir) { require_code('downloads2'); require_code('downloads'); $category_id_remap = array(); $rows = $db->query('SELECT * FROM ' . $table_prefix . 'downloads_categories ORDER BY cid'); $category_id_remap[0] = db_get_first_id(); $orig_parents = array(); foreach ($rows as $row) { $orig_parents[$row['cid']] = array($row['parentid'], $row['title'], $row['cdescription']); $id = add_download_category('', 0, '', '', ''); $category_id_remap[$row['cid']] = $id; $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true); foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'downloads', 'category_name' => strval($id), 'group_id' => $group_id)); } } foreach ($orig_parents as $cid => $bits) { list($orig_parent, $category, $description) = $bits; if ($orig_parent == 0) { $parent_id = db_get_first_id(); } else { $parent_id = $category_id_remap[$orig_parent]; } edit_download_category($category, $parent_id, $description, $category_id_remap[$cid], '', '', '', ''); } $rows = $db->query('SELECT * FROM ' . $table_prefix . 'downloads_downloads'); foreach ($rows as $i => $row) { $rows[$i]['validated'] = 1; $rows[$i]['date'] = $this->mysql_time_to_timestamp($row['date']); } $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'downloads_newdownload'); foreach ($rows2 as $i => $row) { $rows2[$i]['validated'] = 0; $rows2[$i]['totalvotes'] = 0; $rows2[$i]['hits'] = 0; $rows2[$i]['date'] = time(); $rows2[$i]['screenshot'] = ''; } $rows = array_merge($rows, $rows2); foreach ($rows as $row) { $url_parts = explode('/', $row['url']); $original_filename = rawurldecode($url_parts[count($url_parts) - 1]); $url = $row['url']; if (url_is_local($url)) { $url = get_custom_base_url() . '/' . $url; } $comments = ''; $comments_rows = $db->query('SELECT editorialtext FROM ' . $table_prefix . 'downloads_editorials WHERE downloadid=' . $row['lid']); if (array_key_exists(0, $comments_rows)) { $comments = $comments_rows[0]['editorialtext']; } $member = $GLOBALS['FORUM_DRIVER']->get_member_from_username($row['submitter']); if (is_null($member)) { $member = get_member(); } $new_id = add_download($category_id_remap[$row['cid']], $row['title'], $url, html_to_comcode($row['description']), $row['name'], html_to_comcode($comments), NULL, $row['validated'], 1, 1, 1, '', $original_filename, $row['filesize'], 0, 0, NULL, $row['date'], $row['hits'], $row['hits'], $member); if ($row['totalvotes'] != 0) { $real_rating = $row['downloadratingsummary']; // Same scale as ocPortal :) $GLOBALS['SITE_DB']->query_insert('rating', array('rating_for_type' => 'downloads', 'rating_for_id' => strval($new_id), 'rating_member' => get_member(), 'rating_ip' => '127.0.0.1', 'rating_time' => time(), 'rating' => $real_rating)); } // Homepage->Into author $test = $GLOBALS['SITE_DB']->query_value_null_ok('authors', 'url', array('author' => $row['name'])); if (is_null($test)) { require_code('authors'); add_author($row['name'], $row['homepage'], NULL, '', ''); } else { $GLOBALS['SITE_DB']->query_update('authors', array('url' => $row['homepage']), array('author' => $row['name'])); } // Image if ($row['screenshot'] != '' && addon_installed('galleries')) { $image_url = $row['screenshot']; if (url_is_local($image_url)) { $image_url = get_custom_base_url() . '/' . $image_url; } $thumb_url = ''; add_image('', 'download_' . strval($new_id), '', $image_url, $thumb_url, $row['validated'], 1, 1, 1, ''); } } $out = do_template('IMPORT_MESSAGE', array('_GUID' => 'ff9131c37b9e4fa2cff991e3479ae867', 'MESSAGE' => do_lang_tempcode('IMPORT_REBUILD_CACHE', do_lang('IMAGE_THUMBNAILS')))); return $out; }