get_var('SELECT @@autocommit') === '0'; $db->query($nested ? 'SAVEPOINT aop_transaction' : 'START TRANSACTION'); try { $result = $work(); } catch (\Throwable $failure) { $db->query($nested ? 'ROLLBACK TO SAVEPOINT aop_transaction' : 'ROLLBACK'); // What was cached while the rows were there is not true anymore. wp_cache_flush(); throw $failure; } $db->query($nested ? 'RELEASE SAVEPOINT aop_transaction' : 'COMMIT'); return $result; } /** * @return bool True when the tables that an import writes to can roll back (InnoDB). */ public static function supported(): bool { $db = self::wpdb(); foreach ([PageRepository::tableName(), $db->options] as $table) { $engine = $db->get_var($db->prepare( 'SELECT ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = %s', $table )); if (strtolower((string) $engine) !== 'innodb') { return false; } } return true; } }