Cannot access file manager through cron job.

Permalink 1 user found helpful
Hello,

I have a C5 job that searches through all my file sets in the file manager and indexes the files into Elasticsearch when running the job from the dashboard it works correctly but when I tried to automated using cron on Linux it by-passes all the file manager related code. Also if I am logged in and copy the job URL and pasted on the browser it works as well. Has anyone experienced this problem? Thanks in advance for your help.

Blueprint
 
hutman replied on at Permalink Reply
hutman
What version of C5 are you using? What does your job code look like? How are you trying to run in through the cron?
Blueprint replied on at Permalink Reply
Blueprint
Hello,

I am using Core Version - 5.7.5.13.
Here is how crontab 58 10 * * * /usr/bin/wget -t 1 -q -O - "http://site.com/ccm/system/jobs/run_single?auth=token&jID=11" with the proper url from C5.
Here is the code that does all the work.
public function run()
    {
       Cache::disableAll();
       $client = ClientBuilder::create()->build();   
      try{
         $params = ['index' => 'ge_staff_document'];
         $result = $client->indices()->exists($params);
         if($result){
            $response = $client->indices()->delete($params);
         }
      }catch(Exception $e){
         return t('An error has occurred. %s ', $e->getMessage());
      }
      $count = 0; //File counter
      try{


The job works fine if I click "run" on the dashboard or navigate to the url on the browser. Running it from cron it by-passes everything starting from the first loop until the last if statement.
hutman replied on at Permalink Reply
hutman
I think this is the issue - FileSet::getMySets()

If you're running it from the command line there is no user for whom to get the sets, if you're trying to get all the admin's sets you need to pass in the user object into the getMySets function.
Blueprint replied on at Permalink Reply
Blueprint
OK, I will try this approach.

Thank you.
hutman replied on at Permalink Best Answer Reply
hutman
If you want to get all of the sets, not just the ones specific to that user you should be able to do

use Concrete\Core\File\Set\SetList as FileSetList;
$fileSetList = new FileSetList();
$fileSets = $fileSetList->get(9999);
Blueprint replied on at Permalink Reply
Blueprint
That did the trick.

Thank you very much.