Saturday, 20 June 2009

Disable APEX applications after installation

When exporting an application the export file contains exactly the same configuration as your development platform. Thank god. However when moving an application from development to test or production environments you might want some features disabled.

Recently I created a script that after deployment disables some development features.
Here is a short script that disables the following features from all running applications

  • disable DEBUG mode.

  • disable developer toolbar + edit links.

  • sets application alias to application id.

  • places the application in RUN only mode.



DECLARE
      CURSOR c_apps
      IS
        select application_id as app_id
        from apex_applications;

      l_flow_status VARCHAR2(100) := 'AVAILABLE';
      l_debug       VARCHAR2(10) := '0'; -- 0 = NO, 1 = YES
      l_app_alias   VARCHAR2(10);
BEGIN
      -- IDENTIFY FLOW_APPLICAITON SECURITY GROUP
      wwv_flow_api.set_security_group_id(p_security_group_id=>9999999999999999);

      FOR r_app IN c_apps
      LOOP
        l_app_alias := to_char(r_app.app_id);
        -- SET APPLICATION
        wwv_flow.g_flow_id := r_app.app_id;
        wwv_flow_api.g_id_offset := 0;

        -- DISABLE DEBUGGING
        wwv_flow_api.set_enable_app_debugging(P_FLOW_ID => wwv_flow.g_flow_id,
                                              P_DEBUGGING  => l_debug);
        -- SET APPLICATION TO ONLY AVAILABLE
        wwv_flow_api.set_flow_status(P_FLOW_ID => wwv_flow.g_flow_id,
                                      P_FLOW_STATUS => l_flow_status);                                 
        -- REWRITE APPLICATION ALIAS
        wwv_flow_api.SET_APPLICATION_ALIAS(P_FLOW_ID => wwv_flow.g_flow_id,
                                           P_ALIAS => l_app_alias);
        -- SET APPLICATION RUN ONLY
        wwv_flow_api.SET_BUILD_STATUS_RUN_ONLY(P_FLOW_ID => wwv_flow.g_flow_id);
      END LOOP;
      COMMIT;
END;
/