/**
  * Run import
  * @param string $since
  * @param string $until
  * @param int $accountsOffset
  * @param int $accountsCount
  * @param array $accountsIds
  * @throws Exception
  */
 public function import($since = '-14 days', $until = 'today', $accountsOffset = 0, $accountsCount = 0, $accountsIds = array())
 {
     $this->_fbApi->runId = $this->runId . '-' . $this->configurationId;
     //@TODO DEBUG
     $this->_populateSapiTableCache();
     $defaultDate = new \DateTime("now", new \DateTimeZone(self::$TIME_ZONE));
     $this->defaultEndTime = $defaultDate->format(\DateTime::ATOM);
     $this->defaultEndDate = $defaultDate->format('Y-m-d\\T00:00:00P');
     $this->defaultInsightsDate = $defaultDate->sub(\DateInterval::createFromDateString("1 days"))->format('Y-m-d\\T00:00:00P');
     $this->tmpDir = sprintf('%s/%s-%s', "/tmp/ex-fb", date('Ymd-His'), uniqid());
     mkdir($this->tmpDir, 0777, true);
     if (!$this->storageApi->tableExists($this->bucket . '.' . self::ACCOUNTS_TABLE_ID)) {
         $this->log('Accounts table does not exist in configuration', array(), 0, true);
         return;
     }
     $accountsCsv = $this->storageApi->exportTable($this->bucket . '.' . self::ACCOUNTS_TABLE_ID);
     $accounts = \Keboola\StorageApi\Client::parseCsv($accountsCsv);
     if (!count($accounts)) {
         $this->log('No accounts in configuration table', array(), 0, true);
     }
     // Create files for each configuration row
     $this->_prepareCsvFiles();
     // Iterate through each configuration row
     foreach ($this->runConfig as $queryNumber => $query) {
         $this->currentConfigRowNumber = $queryNumber + 1;
         $accountsCounter = 0;
         foreach ($accounts as $account) {
             if (!isset($account["valid"]) || !$account['valid']) {
                 continue 1;
             }
             // Run for the account only if specified or offset and count are matching
             if (!(count($accountsIds) && in_array($account['id'], $accountsIds) || !count($accountsIds) && $accountsCounter >= $accountsOffset && ($accountsCount == 0 || $accountsCounter < $accountsOffset + $accountsCount))) {
                 $accountsCounter++;
                 continue 1;
             }
             $accountsCounter++;
             if (!isset($account['id']) || !isset($account['token'])) {
                 $this->log('Wrong configuration of accounts table', array(), 0, true);
                 continue 1;
             }
             \NDebugger::timer('account');
             $this->_parseQuery($account, $query, $since, $until, $this->_csvFiles[$queryNumber]["handle"]);
         }
         $this->_uploadCsvFile($queryNumber, $query->table);
         $this->log("Extraction of query {$queryNumber} finished", array('queryNumber' => $query), \NDebugger::timer('account'), false);
     }
 }