<?php
// NOTE post_uninstall needs to be not function, and it MUST be included into manifest file
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

post_uninstall();

function post_uninstall()
{
    $adb = DBManagerFactory::getInstance();
    // Drop tables tables
    if(isset($GLOBALS['mi_remove_tables']) && $GLOBALS['mi_remove_tables']) {
        $GLOBALS['log']->debug("AnalyticReporting:: Remove tables is set to true");
        dropTables($adb);
    }
}

/**
 * Drop tables after uninstall
 */
function dropTables($adb)
{
    $adb->query("DROP TABLE IF EXISTS advancedreports_widgets;");
    $adb->query("DROP TABLE IF EXISTS advancedreports_dashboards;");
    $adb->query("DROP TABLE IF EXISTS advancedreports_logs;");
    $adb->query("DROP TABLE IF EXISTS advancedreports_intervals;");
    $adb->query("DROP TABLE IF EXISTS advancedreports_table_mapping;");
    $adb->query("DROP TABLE IF EXISTS advancedreports_blocks;");
    $adb->query("DROP TABLE IF EXISTS advancedreports_fields;");
    $adb->query("DROP TABLE IF EXISTS advancedreports_modules;");
    $adb->query("DROP TABLE IF EXISTS advancedreports_config;");
    $adb->query("DROP TABLE IF EXISTS advancedreports_jobs;");
    $adb->query("DROP TABLE IF EXISTS advancedreports_templates;");
    $adb->query("DROP TABLE IF EXISTS advancedreports_schedule;");
    $adb->query("DROP TABLE IF EXISTS advancedreports_schedule_g;");
    $adb->query("DROP TABLE IF EXISTS advancedreports_schedule_r;");
    $adb->query("DROP TABLE IF EXISTS advancedreports_schedule_u;");
    $adb->query("DROP TABLE IF EXISTS advancedreports_sharedgroups;");
    $adb->query("DROP TABLE IF EXISTS advancedreports_sharedusers;");
    $adb->query("DROP TABLE IF EXISTS advancedreports_categories;");
    $adb->query("DROP TABLE IF EXISTS advancedreports;");

    echo "Tables removed successfully\n<br />";
}