checkPartByIdentifier($identifiers, $name)) { return true; } return false; } /** * @return void */ public function clearListedMultipartBackups() { $this->listedMultipartBackups = []; } public function isListedMultipartBackup(string $filename, bool $shouldAddBackup = true) { $id = $this->extractBackupIdFromFilename($filename); if (in_array($id, $this->listedMultipartBackups)) { return true; } if ($shouldAddBackup) { $this->listedMultipartBackups[] = $id; } return false; } /** * @param string $filename * @return string */ public function extractBackupIdFromFilename(string $filename) { if (strpos($filename, '.' . PartIdentifier::DATABASE_PART_IDENTIFIER . '.' . DatabaseImporter::FILE_FORMAT) !== false) { return $this->extractBackupIdFromDatabaseBackupFilename($filename); } $fileInfos = explode('_', $filename); $fileInfos = $fileInfos[count($fileInfos) - 1]; return explode('.', $fileInfos)[0]; } /** * @param string $filename * @return string */ protected function extractBackupIdFromDatabaseBackupFilename(string $filename) { // This is required if the table prefix contains underscore like wp_some $filename = str_replace('.' . PartIdentifier::DATABASE_PART_IDENTIFIER . '.' . DatabaseImporter::FILE_FORMAT, '', $filename); // Get position of last dot . in filename $lastDotPosition = strrpos($filename, '.'); // Get filename until last dot to remove the table prefix $filename = substr($filename, 0, $lastDotPosition); $fileInfos = explode('_', $filename); return $fileInfos[count($fileInfos) - 1]; } }