Esempio n. 1
0
/**
 * Note: the body of this function is by intention not enclosed in a try/catch block. We wan't the calling sections to catch and handle exceptions themself.
 */
function newsletter_migrate_country_field()
{
    /*
    TEST
                    $countryId = 0;
    $text = 'Switzerland';
                    $objText= \Cx\Lib\UpdateUtil::sql("SELECT `id` FROM `".DBPREFIX."core_text` WHERE `section` = 'core' AND `key` = 'core_country_name' AND `text` = '".contrexx_raw2db($text)."'");
                    if (!$objResult->EOF) {
                        $countryId = $objText->fields['id'];
                    }
    \DBG::dump($countryId);
    return;
    */
    ///////////////////////////
    // MIGRATE COUNTRY FIELD //
    ///////////////////////////
    // 1. backup country column to country_old
    if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_newsletter_user', 'country')) {
        \Cx\Lib\UpdateUtil::sql('ALTER TABLE `' . DBPREFIX . 'module_newsletter_user` CHANGE `country` `country_old` VARCHAR(255) NOT NULL DEFAULT \'\'');
    }
    // 2. add new column country_id (format int)
    if (!\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_newsletter_user', 'country_id')) {
        \Cx\Lib\UpdateUtil::sql('ALTER TABLE `' . DBPREFIX . 'module_newsletter_user` ADD `country_id` SMALLINT( 5 ) UNSIGNED NOT NULL DEFAULT \'0\' AFTER `country_old`');
    }
    // 3. migrate to new country format (using IDs)
    if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_newsletter_user', 'country_old')) {
        $objResult = \Cx\Lib\UpdateUtil::sql('SELECT `id`, `country_old` FROM `' . DBPREFIX . 'module_newsletter_user` WHERE `country_id` = 0 AND `country_old` <> \'\'');
        if ($objResult->RecordCount()) {
            while (!$objResult->EOF) {
                // try setting country_id based on a guess from country_old
                $countryId = 0;
                $objText = \Cx\Lib\UpdateUtil::sql("SELECT `id` FROM `" . DBPREFIX . "core_text` WHERE `section` = 'core' AND `key` = 'core_country_name' AND `text` = '" . contrexx_raw2db($objResult->fields['country_old']) . "'");
                if (!$objResult->EOF) {
                    $countryId = $objText->fields['id'];
                }
                \Cx\Lib\UpdateUtil::sql('UPDATE `' . DBPREFIX . 'module_newsletter_user` SET `country_id` = \'' . contrexx_raw2db($countryId) . '\', `country_old` = \'\' WHERE `id` = ' . $objResult->fields['id']);
                if (!checkTimeoutLimit()) {
                    return 'timeout';
                }
                $objResult->MoveNext();
            }
        }
        // backup literal country name in field notes
        if (!\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_newsletter_user', 'notes')) {
            if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_newsletter_user', 'fax')) {
                $column = 'fax';
            } else {
                // versions pre 3.0.0 didn't have the column 'fax' yet
                $column = 'phone';
            }
            \Cx\Lib\UpdateUtil::sql('ALTER TABLE `' . DBPREFIX . 'module_newsletter_user` ADD `notes` text NOT NULL AFTER `' . $column . '`');
        }
        \Cx\Lib\UpdateUtil::sql('UPDATE `' . DBPREFIX . 'module_newsletter_user` SET `notes` = `country_old`');
        // drop obsolete column country_old'
        \Cx\Lib\UpdateUtil::sql('ALTER TABLE `' . DBPREFIX . 'module_newsletter_user` DROP `country_old`');
    }
    ////////////////////////////////
    // END: MIGRATE COUNTRY FIELD //
    ////////////////////////////////
}
Esempio n. 2
0
/**
 * Cloudrexx
 *
 * @link      http://www.cloudrexx.com
 * @copyright Cloudrexx AG 2007-2015
 *
 * According to our dual licensing model, this program can be used either
 * under the terms of the GNU Affero General Public License, version 3,
 * or under a proprietary license.
 *
 * The texts of the GNU Affero General Public License with an additional
 * permission and of our proprietary license can be found at and
 * in the LICENSE file you have received along with this program.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * "Cloudrexx" is a registered trademark of Cloudrexx AG.
 * The licensing of the program under the AGPLv3 does not imply a
 * trademark license. Therefore any rights, title and interest in
 * our trademarks remain entirely with us.
 */
function _utf8Update()
{
    global $objUpdate, $_DBCONFIG, $objDatabase, $_ARRAYLANG, $_CORELANG;
    $preferedCollation = 'utf8_unicode_ci';
    $usedCollation = '';
    $result = true;
    // fetch currently used collation
    try {
        $objResult = \Cx\Lib\UpdateUtil::sql('SHOW CREATE TABLE `' . DBPREFIX . 'access_users`');
        if ($objResult->EOF) {
            setUpdateMsg(sprintf($_ARRAYLANG['TXT_UNABLE_GETTING_DATABASE_TABLE_STRUCTURE'], DBPREFIX . 'access_users'));
            return false;
        }
        $createStatement = $objResult->fields['Create Table'];
        // note: if charset latin1 is used, collation won't be set
        $matches = array();
        if (preg_match('/COLLATE=([a-z_0-9]*)/', $createStatement, $matches)) {
            $usedCollation = $matches[1];
        }
        \DBG::dump('Currently used collation: ' . $usedCollation);
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    // fetch available collations
    $arrCollations = _getUtf8Collations();
    if (!is_array($arrCollations)) {
        return $arrCollations;
    }
    if (!isset($_SESSION['contrexx_update']['update']['core'])) {
        $_SESSION['contrexx_update']['update']['core'] = array();
    }
    // note: $usedCollation is the currently used collation.
    // in case $usedCollation is non-utf8, then the following var
    // won't be set. This will cause the update system to ask the user
    // to select an utf8 collation.
    if (in_array($usedCollation, $arrCollations)) {
        $_SESSION['contrexx_update']['update']['core']['utf8_collation'] = $usedCollation;
    }
    if (isset($_DBCONFIG['charset']) && $_DBCONFIG['charset'] == 'utf8') {
        // do not update templates if they should be utf8 already
        $_SESSION['contrexx_update']['update']['utf'] = true;
    }
    // show dialog to select utf8 collation
    if (empty($_SESSION['contrexx_update']['update']['core']['utf8_collation'])) {
        if (isset($_POST['dbCollation']) && in_array($objUpdate->stripslashes($_POST['dbCollation']), $arrCollations)) {
            $_SESSION['contrexx_update']['update']['core']['utf8_collation'] = $objUpdate->stripslashes($_POST['dbCollation']);
        } else {
            $collationMenu = '<select name="dbCollation">';
            foreach ($arrCollations as $collation) {
                $collationMenu .= '<option value="' . $collation . '"' . ($collation == $preferedCollation ? ' selected="selected"' : '') . '>' . $collation . '</option>';
            }
            $collationMenu .= '</select><br />';
            setUpdateMsg($_ARRAYLANG['TXT_SELECT_DB_COLLATION'], 'title');
            setUpdateMsg(sprintf($_ARRAYLANG['TXT_SELECT_DB_COLLATION_MSG'] . '<br /><br />', $collationMenu), 'msg');
            setUpdateMsg('<input type="submit" value="' . $_CORELANG['TXT_CONTINUE_UPDATE'] . '" name="updateNext" /><input type="hidden" name="processUpdate" id="processUpdate" />', 'button');
            return false;
        }
    }
    // WRITE COLLATION TO CONFIG FILE IF NECESSARY
    if (empty($_DBCONFIG['collation'])) {
        \DBG::msg('New collation set in _utf8Update(): ' . $_SESSION['contrexx_update']['update']['core']['utf8_collation']);
        // configuration.php will get written by core.php's _writeNewConfigurationFile()
        $_DBCONFIG['collation'] = $_SESSION['contrexx_update']['update']['core']['utf8_collation'];
        // IMPORTANT!
        // setting result to 'charset_changed' will cause a reinitialization of the update system
        // to ensure that the db-connections use the proper charset/collation
        $result = 'charset_changed';
    }
    // SET DATABASE CHARSET AND COLLATION
    try {
        $objDbStatement = \Cx\Lib\UpdateUtil::sql("SHOW CREATE DATABASE `" . $_DBCONFIG['database'] . "`");
        if (!preg_match('#DEFAULT\\sCHARACTER\\sSET\\sutf8\\sCOLLATE\\s' . $_SESSION['contrexx_update']['update']['core']['utf8_collation'] . '#s', $objDbStatement->fields['Create Database'])) {
            \Cx\Lib\UpdateUtil::sql("ALTER DATABASE `" . $_DBCONFIG['database'] . "` DEFAULT CHARACTER SET utf8 COLLATE " . $objUpdate->addslashes($_SESSION['contrexx_update']['update']['core']['utf8_collation']));
        }
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    // CHANGE TABLE CHARSET AND COLLATION
    $arrContrexxTables = array(DBPREFIX . 'access_group_dynamic_ids', DBPREFIX . 'access_group_static_ids', DBPREFIX . 'access_rel_user_group', DBPREFIX . 'access_settings', DBPREFIX . 'access_users', DBPREFIX . 'access_user_attribute', DBPREFIX . 'access_user_attribute_name', DBPREFIX . 'access_user_attribute_value', DBPREFIX . 'access_user_core_attribute', DBPREFIX . 'access_user_groups', DBPREFIX . 'access_user_mail', DBPREFIX . 'access_user_network', DBPREFIX . 'access_user_profile', DBPREFIX . 'access_user_title', DBPREFIX . 'access_user_validity', DBPREFIX . 'module_block_blocks', DBPREFIX . 'module_block_categories', DBPREFIX . 'module_block_rel_lang_content', DBPREFIX . 'module_block_rel_pages', DBPREFIX . 'module_block_settings', DBPREFIX . 'module_blog_categories', DBPREFIX . 'module_blog_comments', DBPREFIX . 'module_blog_messages', DBPREFIX . 'module_blog_messages_lang', DBPREFIX . 'module_blog_message_to_category', DBPREFIX . 'module_blog_networks', DBPREFIX . 'module_blog_networks_lang', DBPREFIX . 'module_blog_settings', DBPREFIX . 'module_blog_votes', DBPREFIX . 'module_calendar', DBPREFIX . 'module_calendar_categories', DBPREFIX . 'module_calendar_form_data', DBPREFIX . 'module_calendar_form_fields', DBPREFIX . 'module_calendar_registrations', DBPREFIX . 'module_calendar_settings', DBPREFIX . 'module_calendar_style', DBPREFIX . 'module_checkout_settings_general', DBPREFIX . 'module_checkout_settings_mails', DBPREFIX . 'module_checkout_settings_yellowpay', DBPREFIX . 'module_checkout_transactions', DBPREFIX . 'module_contact_form', DBPREFIX . 'module_contact_form_data', DBPREFIX . 'module_contact_form_field', DBPREFIX . 'module_contact_form_field_lang', DBPREFIX . 'module_contact_form_lang', DBPREFIX . 'module_contact_form_submit_data', DBPREFIX . 'module_contact_recipient', DBPREFIX . 'module_contact_recipient_lang', DBPREFIX . 'module_contact_settings', DBPREFIX . 'backend_areas', DBPREFIX . 'backups', DBPREFIX . 'content_node', DBPREFIX . 'content_page', DBPREFIX . 'core_country', DBPREFIX . 'core_mail_template', DBPREFIX . 'core_setting', DBPREFIX . 'core_text', DBPREFIX . 'ids', DBPREFIX . 'languages', DBPREFIX . 'lib_country', DBPREFIX . 'log', DBPREFIX . 'log_entry', DBPREFIX . 'modules', DBPREFIX . 'module_repository', DBPREFIX . 'sessions', DBPREFIX . 'settings', DBPREFIX . 'settings_image', DBPREFIX . 'settings_smtp', DBPREFIX . 'skins', DBPREFIX . 'module_data_categories', DBPREFIX . 'module_data_messages', DBPREFIX . 'module_data_messages_lang', DBPREFIX . 'module_data_message_to_category', DBPREFIX . 'module_data_placeholders', DBPREFIX . 'module_data_settings', DBPREFIX . 'module_directory_categories', DBPREFIX . 'module_directory_dir', DBPREFIX . 'module_directory_inputfields', DBPREFIX . 'module_directory_levels', DBPREFIX . 'module_directory_mail', DBPREFIX . 'module_directory_rel_dir_cat', DBPREFIX . 'module_directory_rel_dir_level', DBPREFIX . 'module_directory_settings', DBPREFIX . 'module_directory_settings_google', DBPREFIX . 'module_directory_vote', DBPREFIX . 'module_docsys', DBPREFIX . 'module_docsys_categories', DBPREFIX . 'module_docsys_entry_category', DBPREFIX . 'module_downloads_category', DBPREFIX . 'module_downloads_category_locale', DBPREFIX . 'module_downloads_download', DBPREFIX . 'module_downloads_download_locale', DBPREFIX . 'module_downloads_group', DBPREFIX . 'module_downloads_group_locale', DBPREFIX . 'module_downloads_rel_download_category', DBPREFIX . 'module_downloads_rel_download_download', DBPREFIX . 'module_downloads_rel_group_category', DBPREFIX . 'module_downloads_settings', DBPREFIX . 'module_ecard_ecards', DBPREFIX . 'module_ecard_settings', DBPREFIX . 'module_egov_configuration', DBPREFIX . 'module_egov_orders', DBPREFIX . 'module_egov_products', DBPREFIX . 'module_egov_product_calendar', DBPREFIX . 'module_egov_product_fields', DBPREFIX . 'module_egov_settings', DBPREFIX . 'module_feed_category', DBPREFIX . 'module_feed_news', DBPREFIX . 'module_feed_newsml_association', DBPREFIX . 'module_feed_newsml_categories', DBPREFIX . 'module_feed_newsml_documents', DBPREFIX . 'module_feed_newsml_providers', DBPREFIX . 'module_filesharing', DBPREFIX . 'module_filesharing_mail_template', DBPREFIX . 'module_forum_access', DBPREFIX . 'module_forum_categories', DBPREFIX . 'module_forum_categories_lang', DBPREFIX . 'module_forum_notification', DBPREFIX . 'module_forum_postings', DBPREFIX . 'module_forum_rating', DBPREFIX . 'module_forum_settings', DBPREFIX . 'module_forum_statistics', DBPREFIX . 'module_gallery_categories', DBPREFIX . 'module_gallery_comments', DBPREFIX . 'module_gallery_language', DBPREFIX . 'module_gallery_language_pics', DBPREFIX . 'module_gallery_pictures', DBPREFIX . 'module_gallery_settings', DBPREFIX . 'module_gallery_votes', DBPREFIX . 'module_guestbook', DBPREFIX . 'module_guestbook_settings', DBPREFIX . 'module_jobs', DBPREFIX . 'module_jobs_categories', DBPREFIX . 'module_jobs_location', DBPREFIX . 'module_jobs_rel_loc_jobs', DBPREFIX . 'module_jobs_settings', DBPREFIX . 'module_knowledge_articles', DBPREFIX . 'module_knowledge_article_content', DBPREFIX . 'module_knowledge_categories', DBPREFIX . 'module_knowledge_categories_content', DBPREFIX . 'module_knowledge_settings', DBPREFIX . 'module_knowledge_tags', DBPREFIX . 'module_knowledge_tags_articles', DBPREFIX . 'module_livecam', DBPREFIX . 'module_livecam_settings', DBPREFIX . 'module_market', DBPREFIX . 'module_market_categories', DBPREFIX . 'module_market_mail', DBPREFIX . 'module_market_paypal', DBPREFIX . 'module_market_settings', DBPREFIX . 'module_market_spez_fields', DBPREFIX . 'module_media_settings', DBPREFIX . 'module_mediadir_categories', DBPREFIX . 'module_mediadir_categories_names', DBPREFIX . 'module_mediadir_comments', DBPREFIX . 'module_mediadir_entries', DBPREFIX . 'module_mediadir_forms', DBPREFIX . 'module_mediadir_form_names', DBPREFIX . 'module_mediadir_inputfields', DBPREFIX . 'module_mediadir_inputfield_names', DBPREFIX . 'module_mediadir_inputfield_types', DBPREFIX . 'module_mediadir_inputfield_verifications', DBPREFIX . 'module_mediadir_levels', DBPREFIX . 'module_mediadir_level_names', DBPREFIX . 'module_mediadir_mails', DBPREFIX . 'module_mediadir_mail_actions', DBPREFIX . 'module_mediadir_masks', DBPREFIX . 'module_mediadir_order_rel_forms_selectors', DBPREFIX . 'module_mediadir_rel_entry_categories', DBPREFIX . 'module_mediadir_rel_entry_inputfields', DBPREFIX . 'module_mediadir_rel_entry_levels', DBPREFIX . 'module_mediadir_settings', DBPREFIX . 'module_mediadir_settings_num_categories', DBPREFIX . 'module_mediadir_settings_num_entries', DBPREFIX . 'module_mediadir_settings_num_levels', DBPREFIX . 'module_mediadir_settings_perm_group_forms', DBPREFIX . 'module_mediadir_votes', DBPREFIX . 'module_memberdir_directories', DBPREFIX . 'module_memberdir_name', DBPREFIX . 'module_memberdir_settings', DBPREFIX . 'module_memberdir_values', DBPREFIX . 'module_news', DBPREFIX . 'module_news_categories', DBPREFIX . 'module_news_categories_locale', DBPREFIX . 'module_news_comments', DBPREFIX . 'module_news_locale', DBPREFIX . 'module_news_settings', DBPREFIX . 'module_news_settings_locale', DBPREFIX . 'module_news_stats_view', DBPREFIX . 'module_news_teaser_frame', DBPREFIX . 'module_news_teaser_frame_templates', DBPREFIX . 'module_news_ticker', DBPREFIX . 'module_news_types', DBPREFIX . 'module_news_types_locale', DBPREFIX . 'module_newsletter', DBPREFIX . 'module_newsletter_access_user', DBPREFIX . 'module_newsletter_attachment', DBPREFIX . 'module_newsletter_category', DBPREFIX . 'module_newsletter_confirm_mail', DBPREFIX . 'module_newsletter_email_link', DBPREFIX . 'module_newsletter_email_link_feedback', DBPREFIX . 'module_newsletter_rel_cat_news', DBPREFIX . 'module_newsletter_rel_usergroup_newsletter', DBPREFIX . 'module_newsletter_rel_user_cat', DBPREFIX . 'module_newsletter_settings', DBPREFIX . 'module_newsletter_template', DBPREFIX . 'module_newsletter_tmp_sending', DBPREFIX . 'module_newsletter_user', DBPREFIX . 'module_newsletter_user_title', DBPREFIX . 'module_podcast_category', DBPREFIX . 'module_podcast_medium', DBPREFIX . 'module_podcast_rel_category_lang', DBPREFIX . 'module_podcast_rel_medium_category', DBPREFIX . 'module_podcast_settings', DBPREFIX . 'module_podcast_template', DBPREFIX . 'module_recommend', DBPREFIX . 'module_shop_article_group', DBPREFIX . 'module_shop_attribute', DBPREFIX . 'module_shop_categories', DBPREFIX . 'module_shop_currencies', DBPREFIX . 'module_shop_customer_group', DBPREFIX . 'module_shop_discountgroup_count_name', DBPREFIX . 'module_shop_discountgroup_count_rate', DBPREFIX . 'module_shop_discount_coupon', DBPREFIX . 'module_shop_importimg', DBPREFIX . 'module_shop_lsv', DBPREFIX . 'module_shop_manufacturer', DBPREFIX . 'module_shop_option', DBPREFIX . 'module_shop_orders', DBPREFIX . 'module_shop_order_attributes', DBPREFIX . 'module_shop_order_items', DBPREFIX . 'module_shop_payment', DBPREFIX . 'module_shop_payment_processors', DBPREFIX . 'module_shop_pricelists', DBPREFIX . 'module_shop_products', DBPREFIX . 'module_shop_rel_countries', DBPREFIX . 'module_shop_rel_customer_coupon', DBPREFIX . 'module_shop_rel_discount_group', DBPREFIX . 'module_shop_rel_payment', DBPREFIX . 'module_shop_rel_product_attribute', DBPREFIX . 'module_shop_rel_shipper', DBPREFIX . 'module_shop_shipment_cost', DBPREFIX . 'module_shop_shipper', DBPREFIX . 'module_shop_vat', DBPREFIX . 'module_shop_zones', DBPREFIX . 'stats_browser', DBPREFIX . 'stats_colourdepth', DBPREFIX . 'stats_config', DBPREFIX . 'stats_country', DBPREFIX . 'stats_hostname', DBPREFIX . 'stats_javascript', DBPREFIX . 'stats_operatingsystem', DBPREFIX . 'stats_referer', DBPREFIX . 'stats_requests', DBPREFIX . 'stats_requests_summary', DBPREFIX . 'stats_screenresolution', DBPREFIX . 'stats_search', DBPREFIX . 'stats_spiders', DBPREFIX . 'stats_spiders_summary', DBPREFIX . 'stats_visitors', DBPREFIX . 'stats_visitors_summary', DBPREFIX . 'module_u2u_address_list', DBPREFIX . 'module_u2u_message_log', DBPREFIX . 'module_u2u_sent_messages', DBPREFIX . 'module_u2u_settings', DBPREFIX . 'module_u2u_user_log', DBPREFIX . 'voting_additionaldata', DBPREFIX . 'voting_email', DBPREFIX . 'voting_rel_email_system', DBPREFIX . 'voting_results', DBPREFIX . 'voting_system', DBPREFIX . 'module_feed_newsml_content_item', DBPREFIX . 'module_newsletter_system', DBPREFIX . 'module_newsletter_config', DBPREFIX . 'module_shop_shipment');
    // fetch table collations
    try {
        $objInstalledTable = \Cx\Lib\UpdateUtil::sql("SHOW TABLE STATUS LIKE '" . DBPREFIX . "%'");
        while (!$objInstalledTable->EOF) {
            $arrInstalledTables[$objInstalledTable->fields['Name']] = $objInstalledTable->fields['Collation'];
            $objInstalledTable->MoveNext();
        }
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    // remove existing constraints
    $arrInstalledTableNames = array_keys($arrInstalledTables);
    if (!isset($_SESSION['contrexx_update']['update']['core']['constraints'])) {
        $_SESSION['contrexx_update']['update']['core']['constraints'] = array();
    }
    try {
        foreach ($arrInstalledTableNames as $table) {
            // fetch constraints
            $constraints = \Cx\Lib\UpdateUtil::get_constraints($table);
            // check if any constraints are set
            if (!count($constraints)) {
                continue;
            }
            // backup constraint definition (will be restored after the data has been migrated)
            $_SESSION['contrexx_update']['update']['core']['constraints'][$table] = $constraints;
            // remove constraints
            \Cx\Lib\UpdateUtil::set_constraints($table, array());
        }
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    // migrate tables to utf8 collation
    try {
        foreach ($arrContrexxTables as $table) {
            $converted = false;
            if (in_array($table, $arrInstalledTableNames)) {
                if ($arrInstalledTables[$table] == $_SESSION['contrexx_update']['update']['core']['utf8_collation']) {
                    continue;
                } else {
                    \DBG::msg('UTF-8: Migrate DB-Table: ' . $table);
                    if (!in_array($table . '_new', $arrInstalledTableNames)) {
                        $objTableStructure = \Cx\Lib\UpdateUtil::sql("SHOW CREATE TABLE `" . $table . "`");
                        $objTableStructure->fields['Create Table'] = preg_replace(array('/TABLE `' . $table . '/', '/collate[\\s|=][a-z0-9_]+_bin/i', '/default current_timestamp on update current_timestamp/i', '/character\\s+set[\\s|=][a-z0-9_]+/i', '/collate[\\s|=][a-z0-9_]+/i', '/default charset=[a-z0-9_]+/i'), array('TABLE `' . $table . '_new', 'BINARY', '', '', '', ''), $objTableStructure->fields['Create Table']);
                        \Cx\Lib\UpdateUtil::sql($objTableStructure->fields['Create Table'] . " DEFAULT CHARSET=utf8 COLLATE=" . $objUpdate->addslashes($_SESSION['contrexx_update']['update']['core']['utf8_collation']) . ";\n");
                    }
                    $objResult = \Cx\Lib\UpdateUtil::sql("SELECT COUNT(1) AS rowCount FROM `" . $table . "`");
                    $oriCount = $objResult->fields['rowCount'];
                    $objResult = \Cx\Lib\UpdateUtil::sql("SELECT COUNT(1) AS rowCount FROM `" . $table . "_new`");
                    $newCount = $objResult->fields['rowCount'];
                    if ($oriCount !== $newCount) {
                        // migrate data
                        \Cx\Lib\UpdateUtil::sql("TRUNCATE TABLE `" . $table . "_new`");
                        \Cx\Lib\UpdateUtil::sql("INSERT INTO `" . $table . "_new` SELECT * FROM `" . $table . "`");
                    }
                    \Cx\Lib\UpdateUtil::sql("DROP TABLE `" . $table . "`");
                    $converted = true;
                }
            }
            if (in_array($table . '_new', $arrInstalledTableNames) || $converted) {
                \Cx\Lib\UpdateUtil::sql("RENAME TABLE `" . $table . "_new`  TO `" . $table . "`");
            }
            if (!checkTimeoutLimit()) {
                return 'timeout';
            }
        }
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    // reset constraints
    try {
        foreach ($_SESSION['contrexx_update']['update']['core']['constraints'] as $table => $constraints) {
            // set constraints
            \Cx\Lib\UpdateUtil::set_constraints($table, $constraints);
        }
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    // migrate themes to utf8
    if (!isset($_SESSION['contrexx_update']['update']['utf'])) {
        if (_convertThemes2UTF()) {
            $_SESSION['contrexx_update']['update']['utf'] = true;
        } else {
            return false;
        }
    }
    // $result is either TRUE or 'charset_changed' in case the charset/collation has been changed
    return $result;
}
Esempio n. 3
0
 /**
  * Handles database errors
  *
  * Also migrates old Shop Customers to the User accounts and adds
  * all new settings
  * @return  boolean     false     Always!
  * @throws  Cx\Lib\Update_DatabaseException
  */
 static function errorHandler()
 {
     // Customer
     $table_name_old = DBPREFIX . "module_shop_customers";
     // If the old Customer table is missing, the migration has completed
     // successfully already
     if (!\Cx\Lib\UpdateUtil::table_exist($table_name_old)) {
         return false;
     }
     // Ensure that the ShopSettings (including \Cx\Core\Setting) and Order tables
     // are ready first!
     //DBG::log("Customer::errorHandler(): Adding settings");
     ShopSettings::errorHandler();
     //        \Cx\Core\Country\Controller\Country::errorHandler(); // Called by Order::errorHandler();
     Order::errorHandler();
     Discount::errorHandler();
     \Cx\Core\Setting\Controller\Setting::init('Shop', 'config');
     $objUser = \FWUser::getFWUserObject()->objUser;
     // Create new User_Profile_Attributes
     $index_notes = \Cx\Core\Setting\Controller\Setting::getValue('user_profile_attribute_notes', 'Shop');
     if (!$index_notes) {
         //DBG::log("Customer::errorHandler(): Adding notes attribute...");
         //            $objProfileAttribute = new \User_Profile_Attribute();
         $objProfileAttribute = $objUser->objAttribute->getById(0);
         //DBG::log("Customer::errorHandler(): NEW notes attribute: ".var_export($objProfileAttribute, true));
         $objProfileAttribute->setNames(array(1 => 'Notizen', 2 => 'Notes', 3 => 'Notes', 4 => 'Notes', 5 => 'Notes', 6 => 'Notes'));
         $objProfileAttribute->setType('text');
         $objProfileAttribute->setMultiline(true);
         $objProfileAttribute->setParent(0);
         $objProfileAttribute->setProtection(array(1));
         //DBG::log("Customer::errorHandler(): Made notes attribute: ".var_export($objProfileAttribute, true));
         if (!$objProfileAttribute->store()) {
             throw new \Cx\Lib\Update_DatabaseException("Failed to create User_Profile_Attribute 'notes'");
         }
         //Re initialize shop setting
         \Cx\Core\Setting\Controller\Setting::init('Shop', 'config');
         //DBG::log("Customer::errorHandler(): Stored notes attribute, ID ".$objProfileAttribute->getId());
         if (!(\Cx\Core\Setting\Controller\Setting::set('user_profile_attribute_notes', $objProfileAttribute->getId()) && \Cx\Core\Setting\Controller\Setting::update('user_profile_attribute_notes'))) {
             throw new \Cx\Lib\Update_DatabaseException("Failed to update User_Profile_Attribute 'notes' setting");
         }
         //DBG::log("Customer::errorHandler(): Stored notes attribute ID setting");
     }
     $index_group = \Cx\Core\Setting\Controller\Setting::getValue('user_profile_attribute_customer_group_id', 'Shop');
     if (!$index_group) {
         //            $objProfileAttribute = new \User_Profile_Attribute();
         $objProfileAttribute = $objUser->objAttribute->getById(0);
         $objProfileAttribute->setNames(array(1 => 'Kundenrabattgruppe', 2 => 'Discount group', 3 => 'Kundenrabattgruppe', 4 => 'Kundenrabattgruppe', 5 => 'Kundenrabattgruppe', 6 => 'Kundenrabattgruppe'));
         $objProfileAttribute->setType('text');
         $objProfileAttribute->setParent(0);
         $objProfileAttribute->setProtection(array(1));
         if (!$objProfileAttribute->store()) {
             throw new \Cx\Lib\Update_DatabaseException("Failed to create User_Profile_Attribute 'notes'");
         }
         //Re initialize shop setting
         \Cx\Core\Setting\Controller\Setting::init('Shop', 'config');
         if (!(\Cx\Core\Setting\Controller\Setting::set('user_profile_attribute_customer_group_id', $objProfileAttribute->getId()) && \Cx\Core\Setting\Controller\Setting::update('user_profile_attribute_customer_group_id'))) {
             throw new \Cx\Lib\Update_DatabaseException("Failed to update User_Profile_Attribute 'customer_group_id' setting");
         }
     }
     // For the migration, a temporary flag is needed in the orders table
     // in order to prevent mixing up old and new customer_id values.
     $table_order_name = DBPREFIX . "module_shop_orders";
     if (!\Cx\Lib\UpdateUtil::column_exist($table_order_name, 'migrated')) {
         $query = "\n                ALTER TABLE `{$table_order_name}`\n                  ADD `migrated` TINYINT(1) unsigned NOT NULL default 0";
         \Cx\Lib\UpdateUtil::sql($query);
     }
     // Create missing UserGroups for customers and resellers
     $objGroup = null;
     $group_id_customer = \Cx\Core\Setting\Controller\Setting::getValue('usergroup_id_customer', 'Shop');
     if ($group_id_customer) {
         $objGroup = \FWUser::getFWUserObject()->objGroup->getGroup($group_id_customer);
     }
     if (!$objGroup || $objGroup->EOF) {
         $objGroup = \FWUser::getFWUserObject()->objGroup->getGroups(array('group_name' => 'Shop Endkunden'));
     }
     if (!$objGroup || $objGroup->EOF) {
         $objGroup = new \UserGroup();
         $objGroup->setActiveStatus(true);
         $objGroup->setDescription('Online Shop Endkunden');
         $objGroup->setName('Shop Endkunden');
         $objGroup->setType('frontend');
     }
     //DBG::log("Group: ".var_export($objGroup, true));
     if (!$objGroup) {
         throw new \Cx\Lib\Update_DatabaseException("Failed to create UserGroup for customers");
     }
     //DBG::log("Customer::errorHandler(): Made customer usergroup: ".var_export($objGroup, true));
     if (!$objGroup->store() || !$objGroup->getId()) {
         throw new \Cx\Lib\Update_DatabaseException("Failed to store UserGroup for customers");
     }
     //DBG::log("Customer::errorHandler(): Stored customer usergroup, ID ".$objGroup->getId());
     \Cx\Core\Setting\Controller\Setting::set('usergroup_id_customer', $objGroup->getId());
     if (!\Cx\Core\Setting\Controller\Setting::update('usergroup_id_customer')) {
         throw new \Cx\Lib\Update_DatabaseException("Failed to store UserGroup ID for customers");
     }
     $group_id_customer = $objGroup->getId();
     $objGroup = null;
     $group_id_reseller = \Cx\Core\Setting\Controller\Setting::getValue('usergroup_id_reseller', 'Shop');
     if ($group_id_reseller) {
         $objGroup = \FWUser::getFWUserObject()->objGroup->getGroup($group_id_reseller);
     }
     if (!$objGroup || $objGroup->EOF) {
         $objGroup = \FWUser::getFWUserObject()->objGroup->getGroups(array('group_name' => 'Shop Wiederverkäufer'));
     }
     if (!$objGroup || $objGroup->EOF) {
         $objGroup = new \UserGroup();
         $objGroup->setActiveStatus(true);
         $objGroup->setDescription('Online Shop Wiederverkäufer');
         $objGroup->setName('Shop Wiederverkäufer');
         $objGroup->setType('frontend');
     }
     if (!$objGroup) {
         throw new \Cx\Lib\Update_DatabaseException("Failed to create UserGroup for resellers");
     }
     //DBG::log("Customer::errorHandler(): Made reseller usergroup: ".var_export($objGroup, true));
     if (!$objGroup->store() || !$objGroup->getId()) {
         throw new \Cx\Lib\Update_DatabaseException("Failed to store UserGroup for resellers");
     }
     \Cx\Core\Setting\Controller\Setting::set('usergroup_id_reseller', $objGroup->getId());
     if (!\Cx\Core\Setting\Controller\Setting::update('usergroup_id_reseller')) {
         throw new \Cx\Lib\Update_DatabaseException("Failed to store UserGroup ID for resellers");
     }
     $group_id_reseller = $objGroup->getId();
     $default_lang_id = \FWLanguage::getDefaultLangId();
     $query = "\n            SELECT `customer`.`customerid`,\n                   `customer`.`prefix`, `customer`.`firstname`,\n                   `customer`.`lastname`,\n                   `customer`.`company`, `customer`.`address`,\n                   `customer`.`city`, `customer`.`zip`,\n                   `customer`.`country_id`,\n                   `customer`.`phone`, `customer`.`fax`,\n                   `customer`.`email`,\n                   `customer`.`username`, `customer`.`password`,\n                   `customer`.`company_note`,\n                   `customer`.`is_reseller`,\n                   `customer`.`customer_status`, `customer`.`register_date`,\n                   `customer`.`group_id`\n              FROM `{$table_name_old}` AS `customer`\n             ORDER BY `customer`.`customerid` ASC";
     $objResult = \Cx\Lib\UpdateUtil::sql($query);
     while (!$objResult->EOF) {
         $old_customer_id = $objResult->fields['customerid'];
         if (empty($objResult->fields['email'])) {
             $objResult->fields['email'] = $objResult->fields['username'];
         }
         $email = $objResult->fields['email'];
         $objUser = \FWUser::getFWUserObject()->objUser->getUsers(array('email' => array(0 => $email)));
         // TODO: See whether a User with that username (but different e-mail address) exists!
         $objUser_name = \FWUser::getFWUserObject()->objUser->getUsers(array('username' => array(0 => $objResult->fields['username'])));
         if ($objUser && $objUser_name) {
             $objUser = $objUser_name;
         }
         $objCustomer = null;
         if ($objUser) {
             $objCustomer = self::getById($objUser->getId());
         }
         if (!$objCustomer) {
             $lang_id = Order::getLanguageIdByCustomerId($old_customer_id);
             $lang_id = \FWLanguage::getLangIdByIso639_1($lang_id);
             if (!$lang_id) {
                 $lang_id = $default_lang_id;
             }
             $objCustomer = new Customer();
             if (preg_match('/^(?:frau|mad|mme|signora|miss)/i', $objResult->fields['prefix'])) {
                 $objCustomer->gender('gender_female');
             } elseif (preg_match('/^(?:herr|mon|signore|mister|mr)/i', $objResult->fields['prefix'])) {
                 $objCustomer->gender('gender_male');
                 //                } else {
                 // Other "genders", like "family", "thing", or "it" won't be matched
                 // and are left on "gender_unknown".
                 //DBG::log("*** Prefix {$objResult->fields['prefix']}, UNKNOWN GENDER!");
             }
             //DBG::log("Prefix {$objResult->fields['prefix']}, made gender ".$objCustomer->gender());
             $objCustomer->company($objResult->fields['company']);
             $objCustomer->firstname($objResult->fields['firstname']);
             $objCustomer->lastname($objResult->fields['lastname']);
             $objCustomer->address($objResult->fields['address']);
             $objCustomer->city($objResult->fields['city']);
             $objCustomer->zip($objResult->fields['zip']);
             $objCustomer->country_id($objResult->fields['country_id']);
             $objCustomer->phone($objResult->fields['phone']);
             $objCustomer->fax($objResult->fields['fax']);
             $objCustomer->email($objResult->fields['email']);
             $objCustomer->companynote($objResult->fields['company_note']);
             $objCustomer->active($objResult->fields['customer_status']);
             // Handled by a UserGroup now, see below
             //$objCustomer->setResellerStatus($objResult->fields['is_reseller']);
             $objCustomer->register_date($objResult->fields['register_date']);
             $objCustomer->group_id($objResult->fields['group_id']);
             // NOTE: Mind that the User class has been modified to accept e-mail addresses
             // as usernames!
             $objCustomer->username($objResult->fields['username']);
             // Copy the md5 hash of the password!
             $objCustomer->password = $objResult->fields['password'];
             $objCustomer->setFrontendLanguage($lang_id);
         }
         if ($objResult->fields['is_reseller']) {
             $objCustomer->setGroups($objCustomer->getAssociatedGroupIds() + array($group_id_reseller));
             //DBG::log("Customer::errorHandler(): Added reseller: ".$objCustomer->id());
         } else {
             $objCustomer->setGroups($objCustomer->getAssociatedGroupIds() + array($group_id_customer));
             //DBG::log("Customer::errorHandler(): Added customer: ".$objCustomer->id());
         }
         if (!$objCustomer->store()) {
             //DBG::log(var_export($objCustomer, true));
             throw new \Cx\Lib\Update_DatabaseException("Failed to migrate existing Customer ID " . $old_customer_id . " to Users (Messages: " . join(', ', $objCustomer->error_msg) . ")");
         }
         // Update the Orders table with the new Customer ID.
         // Note that we use the ambiguous old customer ID that may
         // coincide with a new User ID, so to prevent inconsistencies,
         // migrated Orders are marked as such.
         $query = "\n                UPDATE `{$table_order_name}`\n                   SET `customer_id`=" . $objCustomer->id() . ",\n                       `migrated`=1\n                 WHERE `customer_id`={$old_customer_id}\n                   AND `migrated`=0";
         \Cx\Lib\UpdateUtil::sql($query);
         // Drop migrated
         $query = "\n                DELETE FROM `{$table_name_old}`\n                 WHERE `customerid`={$old_customer_id}";
         \Cx\Lib\UpdateUtil::sql($query);
         $objResult->MoveNext();
         if (!checkMemoryLimit() || !checkTimeoutLimit()) {
             return false;
         }
     }
     // Remove the flag, it's no longer needed.
     // (You could also verify that all records have been migrated by
     // querying them with "[...] WHERE `migrated`=0", which *MUST* result
     // in an empty recordset.  This is left as an exercise for the reader.)
     $query = "\n            ALTER TABLE `{$table_order_name}`\n             DROP `migrated`";
     \Cx\Lib\UpdateUtil::sql($query);
     \Cx\Lib\UpdateUtil::drop_table($table_name_old);
     //DBG::log("Updated Customer table and related stuff");
     // Always
     return false;
 }
 public function pageGrouping()
 {
     // Fetch all pages
     if ((!isset($_POST['doGroup']) || isset($_POST['doGroup']) && !$_POST['doGroup']) && empty($_SESSION['contrexx_update']['do_group'])) {
         self::$em->clear();
         return $this->getTreeCode();
     }
     $_SESSION['contrexx_update']['do_group'] = true;
     if (empty($_SESSION['contrexx_update']['similar_pages'])) {
         $_SESSION['contrexx_update']['similar_pages'] = $_POST['similarPages'];
     }
     if (empty($_SESSION['contrexx_update']['remove_pages'])) {
         $_SESSION['contrexx_update']['remove_pages'] = $_POST['removePages'];
     }
     $arrSimilarPages = $_SESSION['contrexx_update']['similar_pages'];
     $pageRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page');
     $nodeRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Node');
     $nodeToRemove = array();
     if (empty($_SESSION['contrexx_update']['node_to_remove'])) {
         $_SESSION['contrexx_update']['node_to_remove'] = array();
     }
     foreach ($arrSimilarPages as $nodeId => $arrPageIds) {
         if (!checkMemoryLimit() || !checkTimeoutLimit()) {
             $_SESSION['contrexx_update']['node_to_remove'] = array_merge(\ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['node_to_remove']), $nodeToRemove);
             return 'timeout';
         }
         foreach ($arrPageIds as $pageId) {
             $page = $pageRepo->find($pageId);
             if ($page && $page->getNode()->getId() != $nodeId) {
                 $nodeToRemove[] = $page->getNode()->getId();
                 $node = $nodeRepo->find($nodeId);
                 $aliases = $page->getAliases();
                 foreach ($aliases as $alias) {
                     $alias->setTarget('[[NODE_' . $node->getId() . '_' . $page->getLang() . ']]');
                     self::$em->persist($alias);
                 }
                 $page->setNode($node);
                 $page->setNodeIdShadowed($node->getId());
                 self::$em->persist($node);
             }
         }
         self::$em->flush();
         unset($_SESSION['contrexx_update']['similar_pages'][$nodeId]);
     }
     $arrRemovePages = $_SESSION['contrexx_update']['remove_pages'];
     $pageToRemove = array();
     if (empty($_SESSION['contrexx_update']['page_to_remove'])) {
         $_SESSION['contrexx_update']['page_to_remove'] = array();
     }
     foreach ($arrRemovePages as $pageId) {
         if (!checkMemoryLimit() || !checkTimeoutLimit()) {
             $_SESSION['contrexx_update']['page_to_remove'] = array_merge(\ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['page_to_remove']), $pageToRemove);
             $_SESSION['contrexx_update']['node_to_remove'] = array_merge(\ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['node_to_remove']), $nodeToRemove);
             return 'timeout';
         }
         $page = $pageRepo->find($pageId);
         if ($page) {
             $pageToRemove[] = $pageId;
             $nodeToRemove[] = $page->getNode()->getId();
         }
         unset($_SESSION['contrexx_update']['remove_pages'][$pageId]);
     }
     $_SESSION['contrexx_update']['page_to_remove'] = array_merge(\ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['page_to_remove']), $pageToRemove);
     $_SESSION['contrexx_update']['node_to_remove'] = array_merge(\ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['node_to_remove']), $nodeToRemove);
     $pageToRemove = $_SESSION['contrexx_update']['page_to_remove'];
     $nodeToRemove = $_SESSION['contrexx_update']['node_to_remove'];
     // Prevent the system from trying to remove the same node more than once
     $pageToRemove = array_unique($pageToRemove);
     foreach ($pageToRemove as $index => $pageId) {
         if (!checkMemoryLimit() || !checkTimeoutLimit()) {
             return 'timeout';
         }
         $page = $pageRepo->find($pageId);
         self::$em->remove($page);
         unset($_SESSION['contrexx_update']['page_to_remove'][$index]);
     }
     self::$em->flush();
     self::$em->clear();
     $nodeToRemove = array_unique($nodeToRemove);
     foreach ($nodeToRemove as $index => $nodeId) {
         if (!checkMemoryLimit() || !checkTimeoutLimit()) {
             return 'timeout';
         }
         $node = $nodeRepo->find($nodeId);
         $nodeRepo->removeFromTree($node);
         // Reset node cache - this is required for the tree to reload its new structure after a node had been removed
         self::$em->clear();
         unset($_SESSION['contrexx_update']['node_to_remove'][$index]);
     }
     return true;
 }
Esempio n. 5
0
/**
 * Cloudrexx
 *
 * @link      http://www.cloudrexx.com
 * @copyright Cloudrexx AG 2007-2015
 *
 * According to our dual licensing model, this program can be used either
 * under the terms of the GNU Affero General Public License, version 3,
 * or under a proprietary license.
 *
 * The texts of the GNU Affero General Public License with an additional
 * permission and of our proprietary license can be found at and
 * in the LICENSE file you have received along with this program.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * "Cloudrexx" is a registered trademark of Cloudrexx AG.
 * The licensing of the program under the AGPLv3 does not imply a
 * trademark license. Therefore any rights, title and interest in
 * our trademarks remain entirely with us.
 */
function _statsUpdate()
{
    global $objDatabase, $objUpdate, $_CONFIG, $_ARRAYLANG;
    // remove redundancies
    if (!isset($_SESSION['contrexx_update']['update']['update_stats'])) {
        $_SESSION['contrexx_update']['update']['update_stats'] = array();
    }
    foreach (array('stats_browser' => array('obsoleteIndex' => 'name', 'unique' => array('name'), 'change' => "`name` `name` VARCHAR(255) BINARY NOT NULL DEFAULT ''"), 'stats_colourdepth' => array('obsoleteIndex' => 'depth', 'unique' => array('depth')), 'stats_country' => array('obsoleteIndex' => 'country', 'unique' => array('country'), 'change' => "`country` `country` VARCHAR(100) BINARY NOT NULL DEFAULT ''"), 'stats_hostname' => array('obsoleteIndex' => 'hostname', 'unique' => array('hostname'), 'change' => "`hostname` `hostname` VARCHAR(255) BINARY NOT NULL DEFAULT ''"), 'stats_operatingsystem' => array('obsoleteIndex' => 'name', 'unique' => array('name'), 'change' => "`name` `name` VARCHAR(255) BINARY NOT NULL DEFAULT ''"), 'stats_referer' => array('obsoleteIndex' => 'uri', 'unique' => array('uri'), 'change' => "`uri` `uri` VARCHAR(255) BINARY NOT NULL DEFAULT ''"), 'stats_requests' => array('obsoleteIndex' => 'page', 'unique' => array('page'), 'count' => 'visits', 'change' => "`page` `page` VARCHAR(255) BINARY NOT NULL DEFAULT ''"), 'stats_requests_summary' => array('obsoleteIndex' => 'type', 'unique' => array('type', 'timestamp')), 'stats_screenresolution' => array('obsoleteIndex' => 'resolution', 'unique' => array('resolution')), 'stats_search' => array('change' => "`name` `name` VARCHAR(100) BINARY NOT NULL DEFAULT ''", 'unique' => array('name')), 'stats_spiders' => array('obsoleteIndex' => 'page', 'unique' => array('page'), 'change' => "`page` `page` VARCHAR(100) BINARY DEFAULT NULL"), 'stats_spiders_summary' => array('obsoleteIndex' => 'unqiue', 'unique' => array('name'), 'change' => "`name` `name` VARCHAR(255) BINARY NOT NULL DEFAULT ''"), 'stats_visitors_summary' => array('obsoleteIndex' => 'type', 'unique' => array('type', 'timestamp')), 'stats_visitors' => array('obsoleteIndex' => 'sid', 'unique' => array('sid'), 'count' => 'timestamp')) as $table => $arrUnique) {
        do {
            if (in_array($table, $_SESSION['contrexx_update']['update']['update_stats'])) {
                break;
            } elseif (!checkTimeoutLimit()) {
                return 'timeout';
            }
            if (isset($arrUnique['change'])) {
                $query = 'ALTER TABLE `' . DBPREFIX . $table . '` CHANGE ' . $arrUnique['change'];
                if ($objDatabase->Execute($query) === false) {
                    return _databaseError($query, $objDatabase->ErrorMsg());
                }
            }
            $arrIndexes = $objDatabase->MetaIndexes(DBPREFIX . $table);
            if ($arrIndexes !== false) {
                if (isset($arrIndexes['unique'])) {
                    $_SESSION['contrexx_update']['update']['update_stats'][] = $table;
                    break;
                } elseif (isset($arrUnique['obsoleteIndex']) && isset($arrIndexes[$arrUnique['obsoleteIndex']])) {
                    $query = 'ALTER TABLE `' . DBPREFIX . $table . '` DROP INDEX `' . $arrUnique['obsoleteIndex'] . '`';
                    if ($objDatabase->Execute($query) === false) {
                        return _databaseError($query, $objDatabase->ErrorMsg());
                    }
                }
            } else {
                setUpdateMsg(sprintf($_ARRAYLANG['TXT_UNABLE_GETTING_DATABASE_TABLE_STRUCTURE'], DBPREFIX . $table));
                return false;
            }
            #DBG::msg("table = $table");
            #DBG::dump($arrUnique);
            if (isset($arrUnique['unique'])) {
                $query = 'SELECT `' . implode('`,`', $arrUnique['unique']) . '`, COUNT(`id`) AS redundancy FROM `' . DBPREFIX . $table . '` GROUP BY `' . implode('`,`', $arrUnique['unique']) . '` ORDER BY redundancy DESC';
                $objEntry = $objDatabase->SelectLimit($query, 10);
                if ($objEntry !== false) {
                    while (!$objEntry->EOF) {
                        if (!checkTimeoutLimit()) {
                            return 'timeout';
                        }
                        $lastRedundancyCount = $objEntry->fields['redundancy'];
                        if ($objEntry->fields['redundancy'] > 1) {
                            $where = array();
                            foreach ($arrUnique['unique'] as $unique) {
                                $where[] = "`" . $unique . "` = '" . addslashes($objEntry->fields[$unique]) . "'";
                            }
                            $query = 'DELETE FROM `' . DBPREFIX . $table . '` WHERE ' . implode(' AND ', $where) . ' ORDER BY `' . (isset($arrUnique['count']) ? $arrUnique['count'] : 'count') . '` LIMIT ' . ($objEntry->fields['redundancy'] - 1);
                            if ($objDatabase->Execute($query) === false) {
                                return _databaseError($query, $objDatabase->ErrorMsg());
                            }
                        } else {
                            break;
                        }
                        $objEntry->MoveNext();
                    }
                } else {
                    return _databaseError($query, $objDatabase->ErrorMsg());
                }
            }
            if ($objEntry->RecordCount() == 0 || $lastRedundancyCount < 2) {
                $query = 'ALTER IGNORE TABLE `' . DBPREFIX . $table . '` ADD UNIQUE `unique` (`' . implode('`,`', $arrUnique['unique']) . '`)';
                if ($objDatabase->Execute($query) == false) {
                    return _databaseError($query, $objDatabase->ErrorMsg());
                }
                $_SESSION['contrexx_update']['update']['update_stats'][] = $table;
                break;
            }
        } while ($objEntry->RecordCount() > 1);
    }
    $arrIndexes = $objDatabase->MetaIndexes(DBPREFIX . 'stats_search');
    if ($arrIndexes !== false) {
        if (isset($arrIndexes['unique'])) {
            $query = 'ALTER TABLE `' . DBPREFIX . 'stats_search` DROP INDEX `unique`';
            if ($objDatabase->Execute($query) === false) {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
        }
        if (empty($_SESSION['contrexx_update']['update']['update_stats']['utf8'])) {
            $query = "ALTER IGNORE TABLE `" . DBPREFIX . "stats_search` CHANGE `name` `name` VARCHAR( 100 ) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL";
            if ($objDatabase->Execute($query)) {
                $_SESSION['contrexx_update']['update']['update_stats']['utf8'] = 1;
                $query = "ALTER IGNORE TABLE `" . DBPREFIX . "stats_search` CHANGE `name` `name` VARCHAR( 100 ) CHARACTER SET binary NOT NULL";
                if ($_SESSION['contrexx_update']['update']['update_stats']['utf8'] == 1 && $objDatabase->Execute($query)) {
                    $_SESSION['contrexx_update']['update']['update_stats']['utf8'] = 2;
                    $query = "ALTER IGNORE TABLE `" . DBPREFIX . "stats_search` CHANGE `name` `name` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL";
                    if ($_SESSION['contrexx_update']['update']['update_stats']['utf8'] == 2 && $objDatabase->Execute($query)) {
                        $_SESSION['contrexx_update']['update']['update_stats']['utf8'] = 3;
                        $query = 'ALTER IGNORE TABLE `' . DBPREFIX . 'stats_search` ADD UNIQUE `unique` (`name`, `external`)';
                        if ($objDatabase->Execute($query) === false) {
                            return _databaseError($query, $objDatabase->ErrorMsg());
                        }
                    } else {
                        return _databaseError($query, $objDatabase->ErrorMsg());
                    }
                } else {
                    return _databaseError($query, $objDatabase->ErrorMsg());
                }
            } else {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
        }
    } else {
        setUpdateMsg(sprintf($_ARRAYLANG['TXT_UNABLE_GETTING_DATABASE_TABLE_STRUCTURE'], DBPREFIX . 'stats_search'));
        return false;
    }
    try {
        \Cx\Lib\UpdateUtil::table(DBPREFIX . 'stats_search', array('id' => array('type' => 'INT(5)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'name' => array('type' => 'VARCHAR(100)', 'binary' => true, 'default' => ''), 'count' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'sid' => array('type' => 'VARCHAR(32)', 'notnull' => true, 'default' => ''), 'external' => array('type' => 'ENUM(\'0\',\'1\')', 'notnull' => true, 'default' => '0')), array('unique' => array('fields' => array('name', 'external'), 'type' => 'UNIQUE')));
        \Cx\Lib\UpdateUtil::table(DBPREFIX . 'stats_requests', array('id' => array('type' => 'INT(9)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'timestamp' => array('type' => 'INT(11)', 'default' => '0', 'notnull' => false, 'after' => 'id'), 'pageId' => array('type' => 'INT(6)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'after' => 'timestamp'), 'page' => array('type' => 'VARCHAR(255)', 'after' => 'pageId', 'default' => '', 'binary' => true), 'visits' => array('type' => 'INT(9)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'after' => 'page'), 'sid' => array('type' => 'VARCHAR(32)', 'after' => 'visits', 'default' => ''), 'pageTitle' => array('type' => 'VARCHAR(250)', 'after' => 'sid')), array('unique' => array('fields' => array('page'), 'type' => 'UNIQUE')));
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    try {
        //2.2.0: new config option 'exclude_identifying_info'
        \Cx\Lib\UpdateUtil::sql('
            INSERT INTO ' . DBPREFIX . 'stats_config (id, name, value, status)
            VALUES (20, "exclude_identifying_info", 1, 0)
            ON DUPLICATE KEY UPDATE `id` = `id`
        ');
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    return true;
}
Esempio n. 6
0
 /**
  * migrate old events to new events table
  */
 protected function migrateEvents()
 {
     $eventId = null;
     $mailTemplateId = null;
     try {
         // migration old events to new event table
         // migrate entries
         $where = '';
         if (!empty($_SESSION['contrexx_update']['calendar']['events'])) {
             $where = ' WHERE `id` > ' . $_SESSION['contrexx_update']['calendar']['events'];
         }
         $result = \Cx\Lib\UpdateUtil::sql("SELECT * FROM `" . CALENDAR_OLD_EVENT_TABLE . "`" . $where . " ORDER BY `id`");
         while (!$result->EOF) {
             $langId = null;
             $registrationFormId = null;
             $mailTemplateId = null;
             $eventId = null;
             $langId = $this->categoryLanguages[$result->fields['catid']];
             $name = $result->fields['name'];
             // added event name to mail title
             $mailTemplateId = $this->addMailTemplate($result->fields['mailTitle'] . ' (' . $name . ')', $result->fields['mailContent'], $langId);
             // insert event
             \Cx\Lib\UpdateUtil::sql("\r\n                    INSERT IGNORE INTO `" . CALENDAR_NEW_EVENT_TABLE . "` (\r\n                        `status`,\r\n                        `catid`,\r\n                        `startdate`,\r\n                        `enddate`,\r\n                        `priority`,\r\n                        `access`,\r\n                        `place`,\r\n                        `link`,\r\n                        `pic`,\r\n                        `attach`,\r\n                        `place_street`,\r\n                        `place_zip`,\r\n                        `place_city`,\r\n                        `place_link`,\r\n                        `place_map`,\r\n                        `org_name`,\r\n                        `org_street`,\r\n                        `org_zip`,\r\n                        `org_city`,\r\n                        `org_email`,\r\n                        `org_link`,\r\n                        `registration_num`,\r\n                        `registration`,\r\n                        `invited_groups`,\r\n                        `registration_notification`,\r\n                        `invited_mails`,\r\n                        `invitation_email_template`,\r\n                        `series_status`,\r\n                        `series_type`,\r\n                        `series_pattern_count`,\r\n                        `series_pattern_weekday`,\r\n                        `series_pattern_day`,\r\n                        `series_pattern_week`,\r\n                        `series_pattern_month`,\r\n                        `series_pattern_type`,\r\n                        `series_pattern_dourance_type`,\r\n                        `series_pattern_end`,\r\n                        `series_pattern_begin`,\r\n                        `series_pattern_exceptions`,\r\n\r\n                        `use_custom_date_display`,\r\n                        `showStartDateList`,\r\n                        `showEndDateList`,\r\n                        `showStartTimeList`,\r\n                        `showEndTimeList`,\r\n                        `showTimeTypeList`,\r\n                        `showStartDateDetail`,\r\n                        `showEndDateDetail`,\r\n                        `showStartTimeDetail`,\r\n                        `showEndTimeDetail`,\r\n                        `showTimeTypeDetail`,\r\n                        `google`,\r\n                        `price`,\r\n                        `place_mediadir_id`,\r\n                        `show_in`,\r\n                        `invitation_sent`,\r\n                        `ticket_sales`,\r\n                        `num_seating`,\r\n                        `confirmed`,\r\n                        `author`,\r\n                        `all_day`,\r\n                        `place_id`,\r\n                        `place_country`,\r\n                        `registration_form`,\r\n                        `email_template`\r\n                    ) VALUES (\r\n                        '" . contrexx_raw2db($result->fields['active']) . "',\r\n                        '" . contrexx_raw2db($result->fields['catid']) . "',\r\n                        '" . contrexx_raw2db($result->fields['startdate']) . "',\r\n                        '" . contrexx_raw2db($result->fields['enddate']) . "',\r\n                        '" . contrexx_raw2db($result->fields['priority']) . "',\r\n                        '" . contrexx_raw2db($result->fields['access']) . "',\r\n                        '" . contrexx_raw2db($result->fields['placeName']) . "',\r\n                        '" . contrexx_raw2db($result->fields['link']) . "',\r\n                        '" . contrexx_raw2db($result->fields['pic']) . "',\r\n                        '" . contrexx_raw2db($result->fields['attachment']) . "',\r\n                        '" . contrexx_raw2db($result->fields['placeStreet']) . "',\r\n                        '" . contrexx_raw2db($result->fields['placeZip']) . "',\r\n                        '" . contrexx_raw2db($result->fields['placeCity']) . "',\r\n                        '" . contrexx_raw2db($result->fields['placeLink']) . "',\r\n                        '" . contrexx_raw2db($result->fields['placeMap']) . "',\r\n                        '" . contrexx_raw2db($result->fields['organizerName']) . "',\r\n                        '" . contrexx_raw2db($result->fields['organizerStreet']) . "',\r\n                        '" . contrexx_raw2db($result->fields['organizerZip']) . "',\r\n                        '" . contrexx_raw2db($result->fields['organizerPlace']) . "',\r\n                        '" . contrexx_raw2db($result->fields['organizerMail']) . "',\r\n                        '" . contrexx_raw2db($result->fields['organizerLink']) . "',\r\n                        '" . contrexx_raw2db($result->fields['num']) . "',\r\n                        '" . contrexx_raw2db($result->fields['registration']) . "',\r\n                        '" . contrexx_raw2db($result->fields['groups']) . "',\r\n                        " . ($result->fields['notification'] ? "'" . contrexx_raw2db($result->fields['notification_address']) . "'" : "''") . ",\r\n                        '',\r\n                        " . $mailTemplateId . ",\r\n                        '" . contrexx_raw2db($result->fields['series_status']) . "',\r\n                        '" . contrexx_raw2db($result->fields['series_type']) . "',\r\n                        '" . contrexx_raw2db($result->fields['series_pattern_count']) . "',\r\n                        '" . contrexx_raw2db($result->fields['series_pattern_weekday']) . "',\r\n                        '" . contrexx_raw2db($result->fields['series_pattern_day']) . "',\r\n                        '" . contrexx_raw2db($result->fields['series_pattern_week']) . "',\r\n                        '" . contrexx_raw2db($result->fields['series_pattern_month']) . "',\r\n                        '" . contrexx_raw2db($result->fields['series_pattern_type']) . "',\r\n                        '" . contrexx_raw2db($result->fields['series_pattern_dourance_type']) . "',\r\n                        '" . contrexx_raw2db($result->fields['series_pattern_end']) . "',\r\n                        '" . contrexx_raw2db($result->fields['series_pattern_begin']) . "',\r\n                        '" . contrexx_raw2db($result->fields['series_pattern_exceptions']) . "',\r\n                        0,\r\n                        1,\r\n                        0,\r\n                        0,\r\n                        0,\r\n                        0,\r\n                        1,\r\n                        1,\r\n                        1,\r\n                        1,\r\n                        1,\r\n                        0,\r\n                        0,\r\n                        0,\r\n                        " . $langId . ",\r\n                        1,\r\n                        0,\r\n                        '',\r\n                        1,\r\n                        " . $_SESSION['contrexx_update']['user_id'] . ",\r\n                        0,\r\n                        0,\r\n                        '',\r\n                        0,\r\n                        0\r\n                    )\r\n                ");
             $eventId = $this->db->Insert_ID();
             // add language fields for event
             \Cx\Lib\UpdateUtil::sql("\r\n                    INSERT IGNORE INTO `" . CALENDAR_NEW_EVENT_FIELD_TABLE . "` (`event_id`, `lang_id`, `title`, `description`, `redirect`)\r\n                    VALUES (\r\n                        " . $eventId . ",\r\n                        " . $langId . ",\r\n                        '" . contrexx_raw2db($name) . "',\r\n                        '" . contrexx_raw2db($result->fields['comment']) . "',\r\n                        ''\r\n                    )\r\n                ");
             // add registration form fields
             $resultFormFields = \Cx\Lib\UpdateUtil::sql("\r\n                    SELECT `id` FROM `" . CALENDAR_OLD_FORM_FIELD_TABLE . "`\r\n                        WHERE `note_id` = " . $result->fields['id'] . "\r\n                ");
             if ($resultFormFields->RecordCount() > 0) {
                 // add registration form
                 $registrationFormId = $this->addRegistrationFormForEvent($name);
                 $formFieldsMap = $this->addRegistrationFormFields($registrationFormId, $result->fields['id'], $langId);
                 \Cx\Lib\UpdateUtil::sql("UPDATE `" . CALENDAR_NEW_EVENT_TABLE . "` SET `registration_form` = " . $registrationFormId . " WHERE `id` = " . $eventId);
                 // add registration data
                 $this->addRegistrationData($result->fields['id'], $eventId, $langId, $formFieldsMap);
             }
             $_SESSION['contrexx_update']['calendar']['events'] = intval($result->fields['id']);
             if (!checkMemoryLimit() || !checkTimeoutLimit()) {
                 return 'timeout';
             }
             // take next event
             $result->MoveNext();
         }
     } catch (\Cx\Lib\UpdateException $e) {
         // remove already inserted data from failed event
         if ($eventId) {
             \Cx\Lib\UpdateUtil::sql("DELETE FROM `" . CALENDAR_NEW_EVENT_TABLE . "` WHERE `id` = " . $eventId);
             \Cx\Lib\UpdateUtil::sql("DELETE FROM `" . CALENDAR_NEW_EVENT_FIELD_TABLE . "` WHERE `event_id` = " . $eventId);
         }
         if ($mailTemplateId) {
             \Cx\Lib\UpdateUtil::sql("DELETE FROM `" . CALENDAR_NEW_MAIL_TABLE . "` WHERE `id` = " . $mailTemplateId);
         }
         return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
     }
     return true;
 }
Esempio n. 7
0
function copyCxFilesToRoot($src, $dst)
{
    static $copiedCxFilesIndex = 0;
    $src = str_replace('\\', '/', $src);
    $dst = str_replace('\\', '/', $dst);
    $dir = opendir($src);
    $arrCurrentFolderStructure = array();
    while ($file = readdir($dir)) {
        if (!in_array($file, array('.', '..'))) {
            $arrCurrentFolderStructure[] = $file;
        }
    }
    sort($arrCurrentFolderStructure);
    if (!isset($_SESSION['contrexx_update']['copiedCxFilesTotal'])) {
        $_SESSION['contrexx_update']['copiedCxFilesTotal'] = 0;
    }
    foreach ($arrCurrentFolderStructure as $file) {
        if (!checkMemoryLimit() || !checkTimeoutLimit()) {
            $_SESSION['contrexx_update']['copiedCxFilesIndex'] = $copiedCxFilesIndex;
            return 'timeout';
        }
        $srcPath = $src . '/' . $file;
        $dstPath = $dst . '/' . $file;
        if (is_dir($srcPath)) {
            \Cx\Lib\FileSystem\FileSystem::make_folder($dstPath);
            $status = copyCxFilesToRoot($srcPath, $dstPath);
            if ($status !== true) {
                return $status;
            }
        } else {
            $copiedCxFilesIndex++;
            if (isset($_SESSION['contrexx_update']['copiedCxFilesIndex']) && $copiedCxFilesIndex <= $_SESSION['contrexx_update']['copiedCxFilesIndex']) {
                continue;
            }
            $_SESSION['contrexx_update']['copiedCxFilesTotal'] = $_SESSION['contrexx_update']['copiedCxFilesTotal'] + 1;
            try {
                // rename the file if its exists on customizing
                if (!renameCustomizingFile($dstPath)) {
                    return false;
                }
                if (!verifyMd5SumOfFile($dstPath, $srcPath)) {
                    if (!backupModifiedFile($dstPath)) {
                        return false;
                    }
                }
                $objFile = new \Cx\Lib\FileSystem\File($srcPath);
                $objFile->copy($dstPath, true);
            } catch (\Exception $e) {
                $copiedCxFilesIndex--;
                $_SESSION['contrexx_update']['copiedCxFilesIndex'] = $copiedCxFilesIndex;
                $_SESSION['contrexx_update']['copiedCxFilesTotal'] = $_SESSION['contrexx_update']['copiedCxFilesTotal'] - 1;
                setUpdateMsg('Folgende Datei konnte nicht installiert werden:<br />' . $dstPath);
                setUpdateMsg('Fehler: ' . $e->getMessage());
                setUpdateMsg('<br />Häufigste Ursache dieses Problems ist, dass zur Ausführung dieses Vorgangs die benötigten Schreibrechte nicht vorhanden sind. Prüfen Sie daher, ob die FTP-Konfiguration in der Datei <strong>config/configuration.php</strong> korrekt eingerichtet ist.');
                return false;
            }
        }
    }
    closedir($dir);
    return true;
}