function sync_old_bynder_media in Bynder 7
2 calls to sync_old_bynder_media()
- bynder_batch_sync_old_bynder_media in includes/
bynder.admin.inc - Tries to sync files previously imported through Bynder to make sure all metadata is up to date.
- bynder_update_7100 in ./
bynder.install - Syncing old Bynder module media to new format.
File
- includes/
bynder.utils.inc, line 86 - utility functions for the bynder module
Code
function sync_old_bynder_media($adminForm = false) {
try {
if (BynderMediaApi::hasSettings() || $adminForm) {
$bynderFiles = load_files_by_filemime('image/bynder');
foreach ($bynderFiles as $key => $file) {
preg_match('/bynder:\\/\\/f\\/([^:\\/\\s]+)\\/i\\/(.*)?(#[\\w\\-]+)?$/', $file->uri, $matches);
$id = $matches[1];
$idHash = $matches[2];
$selectedMedia = BynderMediaApi::getBynderApi()
->getObjectById($id);
if ($selectedMedia) {
bynder_create_media_entry($selectedMedia, $idHash, $file->fid);
}
else {
drupal_set_message(t('Couldn\'t sync file @uri', array(
'@uri' => $file->filename,
)), 'warning');
}
}
}
} catch (Exception $e) {
drupal_set_message(t("There was an error while syncing old Bynder media."), 'error');
watchdog('bynder', $e
->getMessage());
$context['finished'] = 1;
}
}