public static function delete_all_metadatas(Application $app, databox_field $databox_field) { $connection = $databox_field->get_databox()->get_connection(); $builder = $connection->createQueryBuilder(); $builder->select('COUNT(m.id) AS count_id')->from('metadatas', 'm')->where($builder->expr()->eq('m.meta_struct_id', ':meta_struct_id'))->setParameter('meta_struct_id', $databox_field->get_id()); /** @var Statement $stmt */ $stmt = $builder->execute(); $rowcount = $stmt->fetchColumn(); $stmt->closeCursor(); unset($stmt); $n = 0; $increment = 500; $builder->select('m.record_id', 'm.id')->setMaxResults($increment); while ($n < $rowcount) { /** @var Statement $stmt */ $stmt = $builder->setFirstResult($n)->execute(); $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); foreach ($rs as $row) { try { $record = $databox_field->get_databox()->get_record($row['record_id']); $caption_field = new caption_field($app, $databox_field, $record); $caption_field->delete(); $record->set_metadatas([]); unset($caption_field); unset($record); } catch (\Exception $e) { } } $n += $increment; } return; }
public static function delete_all_metadatas(Application $app, databox_field $databox_field) { $sql = 'SELECT count(id) as count_id FROM metadatas WHERE meta_struct_id = :meta_struct_id'; $stmt = $databox_field->get_databox()->get_connection()->prepare($sql); $params = [':meta_struct_id' => $databox_field->get_id()]; $stmt->execute($params); $rowcount = $stmt->rowCount(); $stmt->closeCursor(); $n = 0; $increment = 500; while ($n < $rowcount) { $sql = 'SELECT record_id, id FROM metadatas WHERE meta_struct_id = :meta_struct_id LIMIT ' . $n . ', ' . $increment; $params = [':meta_struct_id' => $databox_field->get_id()]; $stmt = $databox_field->get_databox()->get_connection()->prepare($sql); $stmt->execute($params); $rowcount = $stmt->rowCount(); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); unset($stmt); foreach ($rs as $row) { try { $record = $databox_field->get_databox()->get_record($row['record_id']); $caption_field = new caption_field($app, $databox_field, $record); $caption_field->delete(); $record->set_metadatas([]); $app['phraseanet.SE']->updateRecord($record); unset($caption_field); unset($record); } catch (\Exception $e) { } } $n += $increment; } return; }