function l10n_update_check_translations in Localization update 7
Same name and namespace in other branches
- 6 l10n_update.check.inc \l10n_update_check_translations()
Check updates for active projects and languages.
Parameters
$count: Number of package translations to check.
$before: Unix timestamp, check only updates that haven't been checked for this time.
$limit: Maximum number of updates to do. We check $count translations but we stop after we do $limit updates.
Return value
array
1 call to l10n_update_check_translations()
- l10n_update_cron in ./
l10n_update.module - Implements hook_cron().
File
- ./
l10n_update.check.inc, line 120 - Reusable API for l10n remote updates using $source objects
Code
function l10n_update_check_translations($count, $before, $limit = 1) {
$projects = l10n_update_get_projects();
$updated = $checked = array();
// Select active projects x languages ordered by last checked time
$q = db_select('l10n_update_project', 'p');
$q
->leftJoin('l10n_update_file', 'f', 'p.name = f.project');
$q
->innerJoin('languages', 'l', 'l.language = f.language');
$q
->condition('p.status', 1);
$q
->condition('l.enabled', 1);
// If the file is not there, or it is there, but we did not check since $before.
$q
->condition(db_or()
->isNull('f.status')
->condition(db_and()
->condition('f.status', 1)
->condition('f.last_checked', $before, '<')));
$q
->range(0, $count);
$q
->fields('p', array(
'name',
));
$q
->fields('f');
$q
->addField('l', 'language', 'lang');
$q
->orderBy('last_checked');
$result = $q
->execute();
if ($result) {
$local = (bool) (variable_get('l10n_update_check_mode', L10N_UPDATE_CHECK_ALL) & L10N_UPDATE_CHECK_LOCAL);
$remote = (bool) (variable_get('l10n_update_check_mode', L10N_UPDATE_CHECK_ALL) & L10N_UPDATE_CHECK_REMOTE);
foreach ($result as $check) {
if (count($updated) >= $limit) {
break;
}
$checked[] = $check;
if (!empty($projects[$check->name])) {
$project = $projects[$check->name];
$update = NULL;
$source = l10n_update_source_build($project, $check->lang);
$current = $check->filename ? $check : NULL;
if ($available = l10n_update_source_check($source, $local, $remote)) {
if (!$current || _l10n_update_source_compare($current, $available) == -1 || $current->version != $available->version) {
$update = $available;
}
}
if ($update) {
// The update functions will update data and timestamps too
l10n_update_source_update($update, variable_get('l10n_update_import_mode', LOCALE_IMPORT_KEEP));
$updated[] = $update;
}
elseif ($current) {
// No update available, just update timestamp for this row
db_update('l10n_update_file')
->fields(array(
'last_checked' => REQUEST_TIME,
))
->condition('project', $current->project)
->condition('language', $current->language)
->execute();
}
elseif ($source) {
// Create a new record just for keeping last checked time
$source->last_checked = REQUEST_TIME;
drupal_write_record('l10n_update_file', $source);
}
}
}
}
return array(
$checked,
$updated,
);
}