/** * {@inheritdoc} */ protected function doJob(JobData $data) { $app = $data->getApplication(); $status = [\Bridge_Element::STATUS_PENDING, \Bridge_Element::STATUS_PROCESSING, \Bridge_Element::STATUS_PROCESSING_SERVER]; $params = []; $n = 1; foreach ($status as $stat) { $params[':status' . $n] = $stat; $n++; } $sql = 'SELECT id, account_id FROM bridge_elements' . ' WHERE (status = ' . implode(' OR status = ', array_keys($params)) . ')'; $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); $stmt->closeCursor(); foreach ($rs as $row) { if (!$this->isStarted()) { break; } try { $account = \Bridge_Account::load_account($app, $row['account_id']); $element = new \Bridge_Element($app, $account, $row['id']); $this->log('debug', "process " . $element->get_id() . " with status " . $element->get_status()); if ($element->get_status() == \Bridge_Element::STATUS_PENDING) { $this->upload_element($element); } else { $this->update_element($app, $element); } } catch (\Exception $e) { $this->log('error', sprintf("An error occured : %s", $e->getMessage())); $sql = 'UPDATE bridge_elements SET status = :status WHERE id = :id'; $params = [':status' => \Bridge_Element::STATUS_ERROR, ':id' => $row['id']]; $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); } } }