//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']; }
public function testbuild_relationship_cache() { //unset and reconnect Db to resolve mysqli fetch exeception global $db; unset($db->database); $db->checkConnection(); $relationship = new Relationship(); //execute the method and test if it works and does not throws an exception. try { $relationship->build_relationship_cache(); $this->assertTrue(true); } catch (Exception $e) { $this->fail(); } }
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']; }