Example #1
0
/**
 * This function streamlines the query execution by performing all of the following:
 * 1. Attempt to insert by chunks, if the DB supports it.  So far only mysql does.
 * 2. Handling the query as a head and a body, dealing with chunks or no chunks. 
 * 3. Writing to a log file.
 * @param $head
 * @param $values
 */
function processQueries($head, $values)
{
    if ($GLOBALS['sugar_config']['dbconfig']['db_type'] == 'mysql') {
        $chunks = array_chunk($values, 20, false);
    } else {
        $chunks = array_chunk($values, 1, false);
    }
    foreach ($chunks as $chunk) {
        $query = $head . implode(', ', $chunk);
        $result = loggedQuery($query);
    }
}
Example #2
0
     /* Clear queries */
     unset($GLOBALS['queryHead']);
     unset($GLOBALS['queries']);
     echo microtime_diff($dbStart, microtime()) . "s ";
 }
 //	if ($module == 'Users') {
 //		loggedQuery(file_get_contents(dirname(__FILE__) . '/sql/update-user-preferences.sql'));
 //	}
 if ($module == 'Users') {
     $content = 'YTo0OntzOjg6InRpbWV6b25lIjtzOjE1OiJBbWVyaWNhL1Bob2VuaXgiO3M6MjoidXQiO2k6MTtzOjI0OiJIb21lX1RFQU1OT1RJQ0VfT1JERVJfQlkiO3M6MTA6ImRhdGVfc3RhcnQiO3M6MTI6InVzZXJQcml2R3VpZCI7czozNjoiYTQ4MzYyMTEtZWU4OS0wNzE0LWE0YTItNDY2OTg3YzI4NGY0Ijt9';
     $result = $GLOBALS['db']->query("SELECT id from users where id LIKE 'seed-Users%'");
     while ($row = $GLOBALS['db']->fetchByAssoc($result)) {
         $hashed_id = md5($row['id']);
         $curdt = $datetime = date('Y-m-d H:i:s');
         $stmt = "INSERT INTO user_preferences(id,category,date_entered,date_modified,assigned_user_id,contents) values ('" . $hashed_id . "', 'global', '" . $curdt . "', '" . $curdt . "', '" . $row['id'] . "', '" . $content . "')";
         loggedQuery($stmt);
     }
 }
 if ($module == 'Teams') {
     require_once 'modules/Teams/TeamSet.php';
     require_once 'modules/Teams/TeamSetManager.php';
     TeamSetManager::flushBackendCache();
     $teams_data = array();
     $result = $GLOBALS['db']->query("SELECT id FROM teams");
     while ($row = $GLOBALS['db']->fetchByAssoc($result)) {
         $teams_data[$row['id']] = $row['id'];
     }
     sort($teams_data);
     //Now generate the random team_sets
     $results = array();
     $max_teams_per_set = 10;
Example #3
0
	} //for

	if(!empty($GLOBALS['queryHead']) && !empty($GLOBALS['queries']))
	{
		$dbStart = microtime();
		echo "\n\tHitting DB... ";
		processQueries($GLOBALS['queryHead'], $GLOBALS['queries']);
		/* Clear queries */
		unset($GLOBALS['queryHead']);
		unset($GLOBALS['queries']);
		echo microtime_diff($dbStart, microtime())."s ";
	}

	if ($module == 'Users') {
		loggedQuery(file_get_contents(dirname(__FILE__) . '/sql/update-user-preferences.sql'));
	}

	if ($module == 'Teams') {
		require_once('modules/Teams/TeamSet.php');
        require_once('modules/Teams/TeamSetManager.php');
		TeamSetManager::flushBackendCache();
		$teams_data = array();
		$result = $GLOBALS['db']->query("SELECT id FROM teams");
		while($row = $GLOBALS['db']->fetchByAssoc($result)){
			$teams_data[$row['id']] = $row['id'];
		}

		sort($teams_data);
		//Now generate the random team_sets
		$results = array();