<?xml version="1.0" encoding="UTF-8"?>
<update>
    <step id="10">UPDATE %PREFIX%_user_fields SET usf_name_intern = 'STREET' WHERE usf_name_intern = 'ADDRESS'</step>
    <step id="20">UPDATE %PREFIX%_user_fields SET usf_name = 'SYS_STREET' WHERE usf_name_intern = 'STREET' AND usf_name = 'SYS_ADDRESS'</step>
    <step id="30">UPDATE %PREFIX%_user_fields SET usf_name = 'SYS_STREET' WHERE usf_name_intern = 'STREET' AND usf_name = 'Adresse'</step>
    <step id="40">UPDATE %PREFIX%_user_fields SET usf_name = 'SYS_STREET' WHERE usf_name_intern = 'STREET' AND usf_name = 'Address'</step>
    <step id="45">UPDATE %PREFIX%_preferences SET prf_name = 'dates_default_list_configuration' WHERE prf_name = 'dates_default_list_configurati'</step>
    <step id="50">UpdateStepsCode::updateStep33AddDefaultParticipantList</step>
    <step id="60">UPDATE %PREFIX%_roles SET rol_this_list_view = 1 WHERE rol_visible = 0 AND rol_this_list_view = 2</step>
    <step id="70">UPDATE %PREFIX%_roles SET rol_mail_this_role = 1 WHERE rol_visible = 0 AND rol_mail_this_role > 1</step>
    <step id="80">ALTER TABLE %PREFIX%_roles DROP COLUMN rol_visible</step>
    <step id="90">UpdateStepsCode::updateStep33EventCategory</step>
    <step id="100">UpdateStepsCode::updateStep33SetParticipantsApprovalStates</step>
    <step id="110">ALTER TABLE %PREFIX%_dates ADD COLUMN dat_allow_comments integer not null default 0</step>
    <step id="120">ALTER TABLE %PREFIX%_dates ADD COLUMN dat_additional_guests integer not null default 0</step>
    <step id="130">ALTER TABLE %PREFIX%_user_relation_types ADD COLUMN urt_edit_user boolean not null default '0'</step>
    <step id="140">ALTER TABLE %PREFIX%_dates ADD COLUMN dat_deadline timestamp null default null</step>
    <step id="150">ALTER TABLE %PREFIX%_user_fields ADD COLUMN usf_registration boolean not null default '0'</step>
    <step id="160">UPDATE %PREFIX%_user_fields SET usf_registration = 1 WHERE (usf_name_intern IN ('FIRST_NAME', 'LAST_NAME', 'EMAIL') OR usf_mandatory = 1) AND EXISTS (SELECT 1 FROM %PREFIX%_preferences WHERE prf_name = 'registration_mode' AND prf_value = '1' AND prf_org_id = 1)</step>
    <step id="170">UPDATE %PREFIX%_user_fields SET usf_registration = 1 WHERE EXISTS (SELECT 1 FROM %PREFIX%_preferences WHERE prf_name = 'registration_mode' AND prf_value = '2' AND prf_org_id = 1)</step>
    <step id="180" database="mysql">UPDATE %PREFIX%_preferences pr1 INNER JOIN %PREFIX%_preferences pr2 ON pr2.prf_name = 'registration_mode' AND pr2.prf_value = '0' AND pr1.prf_org_id = pr2.prf_org_id SET pr1.prf_value = '0' WHERE pr1.prf_name = 'registration_enable_module'</step>
    <step id="190" database="pgsql">UPDATE %PREFIX%_preferences pr1 SET prf_value = '0' FROM %PREFIX%_preferences pr2 WHERE pr2.prf_name = 'registration_mode' AND pr2.prf_value = '0' AND pr1.prf_name = 'registration_enable_module' AND pr1.prf_org_id = pr2.prf_org_id</step>
    <step id="200">DELETE FROM %PREFIX%_preferences WHERE prf_name = 'registration_mode'</step>
    <step id="210">INSERT INTO %PREFIX%_roles_rights (ror_name_intern, ror_table)
                   VALUES ('category_view', 'adm_categories'),
                          ('event_participation', 'adm_dates')
    </step>
    <step id="220">UpdateStepsCode::updateStep33VisibleCategories</step>
    <step id="230">ALTER TABLE %PREFIX%_categories DROP COLUMN cat_hidden</step>
    <step id="240">UpdateStepsCode::updateStep33MigrateDatesRightsToFolderRights</step>
    <step id="250">DROP TABLE %PREFIX%_date_role</step>
    <step id="260">UpdateStepsCode::updateStep33AddGlobalCategories</step>
    <step id="270">UPDATE %PREFIX%_announcements SET ann_cat_id = (SELECT cat_id FROM %PREFIX%_categories WHERE cat_name_intern = 'ANN_ALL_ORGANIZATIONS') WHERE ann_global = 1</step>
    <step id="280">UPDATE %PREFIX%_dates SET dat_cat_id = (SELECT cat_id FROM %PREFIX%_categories WHERE cat_name_intern = 'DAT_ALL_ORGANIZATIONS') WHERE dat_global = 1</step>
    <step id="290">ALTER TABLE %PREFIX%_announcements DROP COLUMN ann_global</step>
    <step id="300">ALTER TABLE %PREFIX%_dates DROP COLUMN dat_global</step>
    <step id="310">DELETE FROM %PREFIX%_preferences WHERE prf_name = 'enable_inventory_module'</step>
    <step id="320">DELETE FROM %PREFIX%_categories WHERE cat_type = 'INF'</step>
    <step id="330">ALTER TABLE %PREFIX%_roles DROP COLUMN rol_inventory</step>
    <step id="340">DROP TABLE IF EXISTS %PREFIX%_invent_fields CASCADE</step>
    <step id="350">DROP TABLE IF EXISTS %PREFIX%_invent_data CASCADE</step>
    <step id="360">DROP TABLE IF EXISTS %PREFIX%_invent CASCADE</step>
    <step id="370">ALTER TABLE %PREFIX%_roles_rights ADD COLUMN ror_ror_id_parent integer unsigned</step>
    <step id="380">INSERT INTO %PREFIX%_roles_rights (ror_name_intern, ror_table, ror_ror_id_parent)
                   VALUES ('category_edit', 'adm_categories', (SELECT rr.ror_id FROM %PREFIX%_roles_rights rr WHERE rr.ror_name_intern = 'category_view'))</step>
    <step id="390">ALTER TABLE %PREFIX%_roles_rights ADD CONSTRAINT %PREFIX%_fk_ror_ror_parent FOREIGN KEY (ror_ror_id_parent) REFERENCES %PREFIX%_roles_rights (ror_id) ON DELETE SET NULL ON UPDATE RESTRICT</step>
    <step id="395" database="pgsql">CREATE INDEX IF NOT EXISTS idx_%PREFIX%_msc_part_id ON %PREFIX%_messages_content (msc_part_id)</step>
    <step id="397" database="pgsql">CREATE INDEX IF NOT EXISTS ak_%PREFIX%_shortname ON %PREFIX%_organizations (org_shortname)</step>
    <step id="400" database="pgsql" error="ignore">ALTER INDEX idx_%PREFIX%_mem_rol_usr_id RENAME TO %PREFIX%_idx_mem_rol_usr_id</step>
    <step id="405" database="pgsql" error="ignore">ALTER INDEX ak_mem_rol_usr_id RENAME TO %PREFIX%_idx_mem_rol_usr_id</step>
    <step id="410" database="pgsql">ALTER INDEX idx_%PREFIX%_msc_part_id RENAME TO %PREFIX%_idx_msc_part_id</step>
    <step id="420" database="pgsql">ALTER INDEX ak_%PREFIX%_shortname RENAME TO %PREFIX%_idx_org_shortname</step>
    <step id="430" database="pgsql" error="ignore">ALTER INDEX idx_%PREFIX%_prf_org_id_name RENAME TO %PREFIX%_idx_prf_org_id_name</step>
    <step id="430" database="pgsql" error="ignore">ALTER INDEX idx_prf_org_id_name RENAME TO %PREFIX%_idx_prf_org_id_name</step>
    <step id="440" database="pgsql">ALTER INDEX idx_%PREFIX%_rrd_ror_rol_object_id RENAME TO %PREFIX%_idx_rrd_ror_rol_object_id</step>
    <step id="450" database="pgsql" error="ignore">ALTER INDEX idx_%PREFIX%_session_id RENAME TO %PREFIX%_idx_session_id</step>
    <step id="455" database="pgsql" error="ignore">ALTER INDEX idx_session_id RENAME TO %PREFIX%_idx_session_id</step>
    <step id="460" database="pgsql" error="ignore">ALTER INDEX idx_%PREFIX%_usf_name_intern RENAME TO %PREFIX%_idx_usf_name_intern</step>
    <step id="465" database="pgsql" error="ignore">ALTER INDEX idx_usf_name_intern RENAME TO %PREFIX%_idx_usf_name_intern</step>
    <step id="470" database="pgsql" error="ignore">ALTER INDEX idx_%PREFIX%_usd_usr_usf_id RENAME TO %PREFIX%_idx_usd_usr_usf_id</step>
    <step id="475" database="pgsql" error="ignore">ALTER INDEX ak_usr_usf_id RENAME TO %PREFIX%_idx_usd_usr_usf_id</step>
    <step id="480" database="pgsql" error="ignore">ALTER INDEX idx_%PREFIX%_usr_login_name RENAME TO %PREFIX%_idx_usr_login_name</step>
    <step id="485" database="pgsql" error="ignore">ALTER INDEX ak_usr_login_name RENAME TO %PREFIX%_idx_usr_login_name</step>
    <step id="487" database="mysql" error="ignore">ALTER TABLE %PREFIX%_organizations ADD INDEX ak_%PREFIX%_shortname (org_shortname)</step>
    <step id="490" database="mysql" error="ignore">ALTER TABLE %PREFIX%_members DROP INDEX idx_%PREFIX%_mem_rol_usr_id, ADD INDEX %PREFIX%_idx_mem_rol_usr_id (mem_rol_id, mem_usr_id)</step>
    <step id="495" database="mysql" error="ignore">ALTER TABLE %PREFIX%_members DROP INDEX ak_rol_usr_id, ADD INDEX %PREFIX%_idx_mem_rol_usr_id (mem_rol_id, mem_usr_id)</step>
    <step id="500" database="mysql" error="ignore">ALTER TABLE %PREFIX%_messages_content DROP INDEX idx_%PREFIX%_msc_part_id, ADD INDEX %PREFIX%_idx_msc_part_id (msc_part_id)</step>
    <step id="505" database="mysql" error="ignore">ALTER TABLE %PREFIX%_messages_content ADD INDEX %PREFIX%_idx_msc_part_id (msc_part_id)</step>
    <step id="510" database="mysql" error="ignore">ALTER TABLE %PREFIX%_organizations DROP INDEX ak_%PREFIX%_shortname, ADD INDEX %PREFIX%_idx_org_shortname (org_shortname)</step>
    <step id="520" database="mysql" error="ignore">ALTER TABLE %PREFIX%_preferences DROP INDEX idx_%PREFIX%_prf_org_id_name, ADD INDEX %PREFIX%_idx_prf_org_id_name (prf_org_id, prf_name)</step>
    <step id="525" database="mysql" error="ignore">ALTER TABLE %PREFIX%_preferences DROP INDEX idx_prf_org_id_name, ADD INDEX %PREFIX%_idx_prf_org_id_name (prf_org_id, prf_name)</step>
    <step id="530" database="mysql" error="ignore">ALTER TABLE %PREFIX%_roles_rights_data DROP INDEX idx_%PREFIX%_rrd_ror_rol_object_id, ADD INDEX %PREFIX%_idx_rrd_ror_rol_object_id (rrd_ror_id, rrd_rol_id, rrd_object_id)</step>
    <step id="540" database="mysql" error="ignore">ALTER TABLE %PREFIX%_sessions DROP INDEX idx_%PREFIX%_session_id</step>
    <step id="545" database="mysql" error="ignore">ALTER TABLE %PREFIX%_sessions ADD INDEX %PREFIX%_idx_session_id (ses_session_id)</step>
    <step id="550" database="mysql" error="ignore">ALTER TABLE %PREFIX%_user_fields DROP INDEX idx_%PREFIX%_usf_name_intern, ADD INDEX %PREFIX%_idx_usf_name_intern (usf_name_intern)</step>
    <step id="555" database="mysql" error="ignore">ALTER TABLE %PREFIX%_user_fields DROP INDEX idx_usf_name_intern, ADD INDEX %PREFIX%_idx_usf_name_intern (usf_name_intern)</step>
    <step id="560" database="mysql" error="ignore">ALTER TABLE %PREFIX%_user_data DROP INDEX idx_%PREFIX%_usd_usr_usf_id, ADD INDEX %PREFIX%_idx_usd_usr_usf_id (usd_usr_id, usd_usf_id)</step>
    <step id="565" database="mysql" error="ignore">ALTER TABLE %PREFIX%_user_data DROP INDEX ak_usr_usf_id, ADD INDEX %PREFIX%_idx_usd_usr_usf_id (usd_usr_id, usd_usf_id)</step>
    <step id="570" database="mysql" error="ignore">ALTER TABLE %PREFIX%_users DROP INDEX idx_%PREFIX%_usr_login_name, ADD INDEX %PREFIX%_idx_usr_login_name (usr_login_name)</step>
    <step id="575" database="mysql" error="ignore">ALTER TABLE %PREFIX%_users DROP INDEX ak_usr_login_name, ADD INDEX %PREFIX%_idx_usr_login_name (usr_login_name)</step>
    <step id="580" database="mysql" error="ignore">ALTER TABLE %PREFIX%_organizations DROP INDEX ak_shortname</step>
    <step id="590">CREATE TABLE %PREFIX%_menu
        (
            men_id                      integer unsigned    NOT NULL    AUTO_INCREMENT,
            men_men_id_parent           integer unsigned,
            men_com_id                  integer unsigned,
            men_name_intern             varchar(255),
            men_name                    varchar(255),
            men_description             varchar(4000),
            men_node                    boolean             NOT NULL    DEFAULT '0',
            men_order                   integer unsigned,
            men_standard                boolean             NOT NULL    DEFAULT '0',
            men_url                     varchar(255),
            men_icon                    varchar(2000),
            PRIMARY KEY (men_id)
        )
        ENGINE = InnoDB
        DEFAULT character SET = utf8
        COLLATE = utf8_unicode_ci</step>
    <step id="600">CREATE INDEX %PREFIX%_idx_men_men_id_parent ON %PREFIX%_menu (men_men_id_parent)</step>
    <step id="610">ALTER TABLE %PREFIX%_menu ADD CONSTRAINT %PREFIX%_fk_men_men_parent FOREIGN KEY (men_men_id_parent) REFERENCES %PREFIX%_menu (men_id) ON DELETE SET NULL ON UPDATE RESTRICT</step>
    <step id="620">ALTER TABLE %PREFIX%_menu ADD CONSTRAINT %PREFIX%_fk_men_com_id FOREIGN KEY (men_com_id) REFERENCES %PREFIX%_components (com_id) ON DELETE RESTRICT ON UPDATE RESTRICT</step>
    <step id="630">INSERT INTO %PREFIX%_roles_rights (ror_name_intern, ror_table)
                   VALUES ('menu_view', 'adm_menu')</step>
    <step id="640">UPDATE %PREFIX%_components SET com_name_intern = 'ANNOUNCEMENTS' WHERE com_name_intern = 'ANNOUCEMENTS'</step>
    <step id="650">UpdateStepsCode::updateStep33MigrateToStandardMenu</step>
    <step id="660">UpdateStepsCode::updateStep33DownloadOrgFolderName</step>
    <step id="670">UPDATE %PREFIX%_user_fields SET usf_registration = 1 WHERE usf_name_intern IN ('LAST_NAME', 'FIRST_NAME', 'EMAIL')</step>
    <step id="680">UPDATE %PREFIX%_members SET mem_begin = '2018-04-01' WHERE mem_begin = '0000-00-00'</step>
    <step id="690">ALTER TABLE %PREFIX%_auto_login DROP COLUMN atl_ip_address</step>
    <step id="700">UPDATE %PREFIX%_menu SET men_description = 'SYS_MYLIST_DESC' WHERE men_name_intern = 'mylist'</step>
    <step id="710">UPDATE %PREFIX%_menu SET men_description = 'SYS_MENU_DESC' WHERE men_name_intern = 'menu'</step>
    <step id="720">UPDATE %PREFIX%_preferences SET prf_value = '1' WHERE prf_name = 'dates_may_take_part'</step>
    <step id="730" database="mysql">ALTER TABLE %PREFIX%_roles MODIFY COLUMN rol_cost float</step>
    <step id="740">UpdateStepsCode::updateStep33RemoveExpiredMessengers</step>
    <step>stop</step>
</update>
