Skip to content

Instantly share code, notes, and snippets.

@killes
Last active December 4, 2017 15:04
Show Gist options
  • Save killes/1d8ba1413280bcaf21b943e893dd53e1 to your computer and use it in GitHub Desktop.
Save killes/1d8ba1413280bcaf21b943e893dd53e1 to your computer and use it in GitHub Desktop.
diff --git a/modules/infinite_odoscope/infinite_odoscope.drush.inc b/modules/infinite_odoscope/infinite_odoscope.drush.inc
index 2d96591..532edd8 100644
--- a/modules/infinite_odoscope/infinite_odoscope.drush.inc
+++ b/modules/infinite_odoscope/infinite_odoscope.drush.inc
@@ -80,7 +80,33 @@ function drush_infinite_odoscope_odoscope_queue() {
_odoscope_infinite_execute_view($args_create);
// open the generated file. This sadly depends on executing drush with
// -u 1 because the filename starts with the user ID.
- $handle = fopen('private://1article-update.csv', 'r');
+ $fids = Drupal::entityQuery('file')
+ ->condition('status', FILE_STATUS_PERMANENT, '<>')
+ ->condition('created', REQUEST_TIME - 120, '>')
+ ->condition('filemime', 'text/csv')
+ ->condition('uri', db_like('private://') . '%' . db_like('article-update.csv'), 'LIKE')
+ ->sort('created', 'DESC')
+ ->range(0, 1)
+ ->execute();
+
+ $files = entity_load_multiple('file', $fids);
+ $filecount = count($files);
+ switch ($filecount) {
+ case 0:
+ // No file found, alert slack
+ $ah_env = isset($_ENV['AH_SITE_ENVIRONMENT']) ? $_ENV['AH_SITE_ENVIRONMENT'] : '';
+ $message = t('No file created by odoscope view or file not found on @env.', ['@env' => $ah_env]);
+ Drupal::service('slack.slack_service')->sendMessage($message);
+ break;
+ case 1:
+ $file = reset($files);
+ break;
+ default:
+ // can't happen
+ break;
+ }
+
+ $handle = fopen($file->getFileUri(), 'r');
$rowcount = 0;
if ($handle) {
while (($data = fgetcsv($handle)) !== FALSE) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment