function delete($rel_name)
 {
     require_once "ModuleInstall/ModuleInstaller.php";
     require_once 'modules/Administration/QuickRepairAndRebuild.php';
     $mi = new ModuleInstaller();
     $mi->silent = true;
     $mi->uninstall_relationship("custom/metadata/{$rel_name}MetaData.php");
     // now clear all caches so that our changes are visible
     Relationship::delete_cache();
     $mi->rebuild_tabledictionary();
     $MBmodStrings = $GLOBALS['mod_strings'];
     $GLOBALS['mod_strings'] = return_module_language('', 'Administration');
     $rac = new RepairAndClear();
     $rac->repairAndClearAll(array('clearAll', 'rebuildExtensions'), array($GLOBALS['mod_strings']['LBL_ALL_MODULES']), true, false);
     $GLOBALS['mod_strings'] = $MBmodStrings;
 }
 function delete($rel_name)
 {
     //Remove any fields from layouts
     $rel = $this->get($rel_name);
     if (!empty($rel)) {
         $this->removeFieldsFromDeployedLayout($rel);
     }
     require_once "ModuleInstall/ModuleInstaller.php";
     require_once 'modules/Administration/QuickRepairAndRebuild.php';
     $mi = new ModuleInstaller();
     $mi->silent = true;
     $mi->uninstall_relationship("custom/metadata/{$rel_name}MetaData.php");
     // now clear all caches so that our changes are visible
     Relationship::delete_cache();
     $mi->rebuild_tabledictionary();
     $MBmodStrings = $GLOBALS['mod_strings'];
     $GLOBALS['mod_strings'] = return_module_language('', 'Administration');
     $rac = new RepairAndClear();
     $rac->repairAndClearAll(array('clearAll', 'rebuildExtensions'), array($GLOBALS['mod_strings']['LBL_ALL_MODULES']), true, false);
     $GLOBALS['mod_strings'] = $MBmodStrings;
     //Bug 41070, supercedes the previous 40941 fix in this section
     if (isset($this->relationships[$rel_name])) {
         unset($this->relationships[$rel_name]);
     }
 }
Esempio n. 3
0
 function uninstall_relationships($include_studio_relationships = false)
 {
     $relationships = array();
     //Find and remove studio created relationships.
     global $beanList, $beanFiles, $dictionary;
     //Load up the custom relationship definitions.
     if (file_exists('custom/application/Ext/TableDictionary/tabledictionary.ext.php')) {
         include 'custom/application/Ext/TableDictionary/tabledictionary.ext.php';
     }
     //Find all the relatioships/relate fields involving this module.
     $rels_to_remove = array();
     foreach ($beanList as $mod => $bean) {
         //Some modules like cases have a bean name that doesn't match the object name
         $bean = BeanFactory::getObjectName($mod);
         VardefManager::loadVardef($mod, $bean);
         //We can skip modules that are in this package as they will be removed anyhow
         if (!in_array($mod, $this->modulesInPackage) && !empty($dictionary[$bean]) && !empty($dictionary[$bean]['fields'])) {
             $field_defs = $dictionary[$bean]['fields'];
             foreach ($field_defs as $field => $def) {
                 //Weed out most fields first
                 if (isset($def['type'])) {
                     //Custom relationships created in the relationship editor
                     if ($def['type'] == "link" && !empty($def['relationship']) && !empty($dictionary[$def['relationship']])) {
                         $rel_name = $def['relationship'];
                         $rel_def = $dictionary[$rel_name]['relationships'][$rel_name];
                         //Check against mods to be removed.
                         foreach ($this->modulesInPackage as $removed_mod) {
                             if ($rel_def['lhs_module'] == $removed_mod || $rel_def['rhs_module'] == $removed_mod) {
                                 $dictionary[$rel_name]['from_studio'] = true;
                                 $relationships[$rel_name] = $dictionary[$rel_name];
                             }
                         }
                     }
                     //Custom "relate" fields created in studio also need to be removed
                     if ($def['type'] == 'relate' && isset($def['module'])) {
                         foreach ($this->modulesInPackage as $removed_mod) {
                             if ($def['module'] == $removed_mod) {
                                 require_once 'modules/ModuleBuilder/Module/StudioModule.php';
                                 $studioMod = new StudioModule($mod);
                                 $studioMod->removeFieldFromLayouts($field);
                                 if (isset($def['custom_module'])) {
                                     require_once 'modules/DynamicFields/DynamicField.php';
                                     require_once $beanFiles[$bean];
                                     $seed = new $bean();
                                     $df = new DynamicField($mod);
                                     $df->setup($seed);
                                     //Need to load the entire field_meta_data for some field types
                                     $field_obj = $df->getFieldWidget($mod, $field);
                                     $field_obj->delete($df);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->uninstall_relationship(null, $relationships);
     if (isset($this->installdefs['relationships'])) {
         $relationships = $this->installdefs['relationships'];
         $this->log(translate('LBL_MI_UN_RELATIONSHIPS'));
         foreach ($relationships as $relationship) {
             // remove the metadata entry
             $filename = basename($relationship['meta_data']);
             $pathname = file_exists("custom/metadata/{$filename}") ? "custom/metadata/{$filename}" : "metadata/{$filename}";
             if (isset($GLOBALS['mi_remove_tables']) && $GLOBALS['mi_remove_tables']) {
                 $this->uninstall_relationship($pathname);
             }
             if (file_exists($pathname)) {
                 unlink($pathname);
             }
         }
     }
     if (file_exists("custom/Extension/application/Ext/TableDictionary/{$this->id_name}.php")) {
         unlink("custom/Extension/application/Ext/TableDictionary/{$this->id_name}.php");
     }
     Relationship::delete_cache();
     $this->rebuild_tabledictionary();
 }
 public function testdelete_cache()
 {
     //execute the method and test if it works and does not throws an exception.
     try {
         Relationship::delete_cache();
         $this->assertTrue(true);
     } catch (Exception $e) {
         $this->fail();
     }
 }
Esempio n. 5
0
//clean relationship cache..will be rebuilt upon first access.
if (empty($_REQUEST['silent'])) {
    echo $mod_strings['LBL_REBUILD_REL_DEL_CACHE'];
}
Relationship::delete_cache();
//////////////////////////////////////////////////////////////////////////////
// Remove the "Rebuild Relationships" red text message on admin logins
if (empty($_REQUEST['silent'])) {
    echo $mod_strings['LBL_REBUILD_REL_UPD_WARNING'];
}
// clear the database row if it exists (just to be sure)
$query = "DELETE FROM versions WHERE name='Rebuild Relationships'";
$log->info($query);
$db->query($query);
// insert a new database row to show the rebuild relationships is done
$id = create_guid();
$gmdate = gmdate('Y-m-d H:i:s');
$date_entered = db_convert("'{$gmdate}'", 'datetime');
$query = 'INSERT INTO versions (id, deleted, date_entered, date_modified, modified_user_id, created_by, name, file_version, db_version) ' . "VALUES ('{$id}', '0', {$date_entered}, {$date_entered}, '1', '1', 'Rebuild Relationships', '4.0.0', '4.0.0')";
$log->info($query);
$db->query($query);
$rel = new Relationship();
Relationship::delete_cache();
$rel->build_relationship_cache();
// unset the session variable so it is not picked up in DisplayWarnings.php
if (isset($_SESSION['rebuild_relationships'])) {
    unset($_SESSION['rebuild_relationships']);
}
if (empty($_REQUEST['silent'])) {
    echo $mod_strings['LBL_DONE'];
}
Esempio n. 6
0
    function setUp()
    {
        $this->markTestIncomplete("Skipping unless otherwise specified");
        $admin = new User();
        $GLOBALS['current_user'] = $admin->retrieve('1');
        $GLOBALS['app_list_strings'] = return_app_list_strings_language('en_us');
        //Create the custom relationships
        if (!file_exists('custom/Extension/modules/abc_Test/Ext/Vardefs')) {
            mkdir_recursive('custom/Extension/modules/abc_Test/Ext/Vardefs');
        }
        if (!file_exists('custom/Extension/modules/abc_Test/Ext/Layoutdefs')) {
            mkdir_recursive('custom/Extension/modules/abc_Test/Ext/Layoutdefs');
        }
        if (!file_exists('modules/abc_Test/metadata')) {
            mkdir_recursive('modules/abc_Test/metadata');
        }
        if ($fh = @fopen('modules/abc_Test/metadata/studio.php', 'w+')) {
            $string = <<<EOQ
\$GLOBALS['studioDefs']['abc_Test'] = array(

);
EOQ;
            fputs($fh, $string);
            fclose($fh);
        }
        if ($fh = @fopen('custom/Extension/modules/abc_Test/Ext/Vardefs/test.php', 'w+')) {
            $string = <<<EOQ

<?php
\$dictionary["abc_Test"]["fields"]["abc_test_abc_test"] = array (
  'name' => 'abc_test_abc_test',
  'type' => 'link',
  'relationship' => 'abc_test_abc_test',
  'source' => 'non-db',
  'side' => 'right',
  'vname' => 'LBL_ABC_TEST_ABC_TEST_FROM_ABC_TEST_L_TITLE',
);
?>
<?php
\$dictionary["abc_Test"]["fields"]["abc_test_abc_test_name"] = array (
  'name' => 'abc_test_abc_test_name',
  'type' => 'relate',
  'source' => 'non-db',
  'vname' => 'LBL_ABC_TEST_ABC_TEST_FROM_ABC_TEST_L_TITLE',
  'save' => true,
  'id_name' => 'abc_test_ab6dabc_test_ida',
  'link' => 'abc_test_abc_test',
  'table' => 'abc_test',
  'module' => 'abc_Test',
  'rname' => 'name',
);
?>
<?php
\$dictionary["abc_Test"]["fields"]["abc_test_ab6dabc_test_ida"] = array (
  'name' => 'abc_test_ab6dabc_test_ida',
  'type' => 'link',
  'relationship' => 'abc_test_abc_test',
  'source' => 'non-db',
  'reportable' => false,
  'side' => 'right',
  'vname' => 'LBL_ABC_TEST_ABC_TEST_FROM_ABC_TEST_R_TITLE',
);
?>

EOQ;
            fputs($fh, $string);
            fclose($fh);
        }
        //Create the custom relationships
        if (!file_exists('custom/metadata')) {
            mkdir_recursive('custom/metadata');
        }
        if ($fh = @fopen('custom/metadata/abc_test_abc_testMetaData.php', 'w+')) {
            $string = <<<EOQ

<?php
\$dictionary["abc_test_abc_test"] = array (
  'true_relationship_type' => 'one-to-many',
  'relationships' => 
  array (
    'abc_test_abc_test' => 
    array (
      'lhs_module' => 'abc_Test',
      'lhs_table' => 'abc_test',
      'lhs_key' => 'id',
      'rhs_module' => 'abc_Test',
      'rhs_table' => 'abc_test',
      'rhs_key' => 'id',
      'relationship_type' => 'one-to-many',
      'join_table' => 'abc_test_abc_test_c',
      'join_key_lhs' => 'abc_test_ab6dabc_test_ida',
      'join_key_rhs' => 'abc_test_aed49bc_test_idb',
    ),
  ),
  'table' => 'abc_test_abc_test_c',
  'fields' => 
  array (
    0 => 
    array (
      'name' => 'id',
      'type' => 'varchar',
      'len' => 36,
    ),
    1 => 
    array (
      'name' => 'date_modified',
      'type' => 'datetime',
    ),
    2 => 
    array (
      'name' => 'deleted',
      'type' => 'bool',
      'len' => '1',
      'default' => '0',
      'required' => true,
    ),
    3 => 
    array (
      'name' => 'abc_test_ab6dabc_test_ida',
      'type' => 'varchar',
      'len' => 36,
    ),
    4 => 
    array (
      'name' => 'abc_test_aed49bc_test_idb',
      'type' => 'varchar',
      'len' => 36,
    ),
  ),
  'indices' => 
  array (
    0 => 
    array (
      'name' => 'abc_test_abc_testspk',
      'type' => 'primary',
      'fields' => 
      array (
        0 => 'id',
      ),
    ),
    1 => 
    array (
      'name' => 'abc_test_abc_test_ida1',
      'type' => 'index',
      'fields' => 
      array (
        0 => 'abc_test_ab6dabc_test_ida',
      ),
    ),
    2 => 
    array (
      'name' => 'abc_test_abc_test_alt',
      'type' => 'alternate_key',
      'fields' => 
      array (
        0 => 'abc_test_aed49bc_test_idb',
      ),
    ),
  ),
);
?>


EOQ;
            fputs($fh, $string);
            fclose($fh);
        }
        if (!file_exists('custom/Extension/application/Ext/TableDictionary')) {
            mkdir_recursive('custom/Extension/application/Ext/TableDictionary');
        }
        if ($fh = @fopen('custom/Extension/application/Ext/TableDictionary/abc_test_abc_test.php', 'w+')) {
            $string = <<<EOQ
<?php
include('custom/metadata/abc_test_abc_testMetaData.php');
?>
EOQ;
            fputs($fh, $string);
            fclose($fh);
        }
        $this->rel_guid = create_guid();
        $sql = "INSERT INTO relationships (id, relationship_name, lhs_module, lhs_table, lhs_key, rhs_module, rhs_table, rhs_key, join_table, join_key_lhs, join_key_rhs, relationship_type, reverse, deleted) VALUES ('{$this->rel_guid}', 'abc_test_abc_test', 'abc_Test', 'abc_test', 'id', 'abc_Test', 'abc_test', 'id', 'abc_test_abc_test_c', 'abc_test_ab6abc_test_id', 'abc_test_aed49bc_test_id', 'one-to-many', 0, 0)";
        $GLOBALS['db']->query($sql);
        $rel = new Relationship();
        Relationship::delete_cache();
        $rel->build_relationship_cache();
        $this->moduleList = $GLOBALS['moduleList'];
    }
Esempio n. 7
0
 /**
  * Clears cache.
  */
 protected function cleanCache()
 {
     $mi = new ModuleInstaller();
     $mi->silent = true;
     Relationship::delete_cache();
     $mi->rebuild_vardefs();
     $mi->rebuild_tabledictionary();
 }
 function uninstall_relationship($file)
 {
     if (!file_exists($file)) {
         $GLOBALS['log']->debug('File does not exists : ' . $file);
         return;
     }
     include_once $file;
     $rel_dictionary = $dictionary;
     foreach ($rel_dictionary as $rel_name => $rel_data) {
         $table = $rel_data['table'];
         if ($this->db->tableExists($table)) {
             SugarBean::removeRelationshipMeta($rel_name, $this->db, $table, $rel_dictionary, '');
             $this->db->dropTableName($table);
             Relationship::delete_cache();
             if (!$this->silent) {
                 $GLOBALS['log']->debug('droping table ' . $table);
             }
         }
     }
 }