doBackupFeedsTable($em); } /** * {@inheritdoc} */ public function isApplyable(Application $app) { return $this->tableExists($app['orm.em'], 'feeds'); } /** * {@inheritdoc} */ public function rollback(EntityManager $em, \appbox $appbox, Configuration $conf) { if ($this->tableExists($em, 'feeds_backup')) { $em->getConnection()->getSchemaManager()->renameTable('feeds_backup', 'feeds'); } } /** * Checks whether the table exists or not. * * @param $tableName * * @return boolean */ private function tableExists(EntityManager $em, $table) { return (Boolean) $em->createNativeQuery( 'SHOW TABLE STATUS WHERE Name="'.$table.'" COLLATE utf8_bin ', (new ResultSetMapping())->addScalarResult('Name', 'Name') )->getOneOrNullResult(); } /** * Renames feed table. * * @param EntityManager $em */ private function doBackupFeedsTable(EntityManager $em) { $em->getConnection()->getSchemaManager()->renameTable('feeds', 'feeds_backup'); } }