getAppendix() . $start . '_' . $end; } /** * Moves the given blobs into chunks and assigns a proper record name containing the chunk number. * * @param string $recordName The original archive record name, eg 'Actions_ActionsUrl' * @param array $blobs An array containg a mapping of tableIds to blobs. Eg array(0 => 'blob', 1 => 'subtableBlob', ...) * @return array An array where each blob is moved into a chunk, indexed by recordNames. * eg array('Actions_ActionsUrl_chunk_0_99' => array(0 => 'blob', 1 => 'subtableBlob', ...), * 'Actions_ActionsUrl_chunk_100_199' => array(...)) */ public function moveArchiveBlobsIntoChunks($recordName, $blobs) { $chunks = array(); foreach ($blobs as $tableId => $blob) { $name = $this->getRecordNameForTableId($recordName, $tableId); if (!array_key_exists($name, $chunks)) { $chunks[$name] = array(); } $chunks[$name][$tableId] = $blob; } return $chunks; } /** * Detects whether a recordName like 'Actions_ActionUrls_chunk_0_99' or 'Actions_ActionUrls' belongs to a * chunk or not. * * To be a valid recordName that belongs to a chunk it must end with '_chunk_NUMERIC_NUMERIC'. * * @param string $recordName * @return bool */ public function isRecordNameAChunk($recordName) { $posAppendix = $this->getEndPosOfChunkAppendix($recordName); if (false === $posAppendix) { return false; } // will contain "0_99" of "chunk_0_99" $blobId = substr($recordName, $posAppendix); return $this->isChunkRange($blobId); } private function isChunkRange($blobId) { $blobId = explode('_', $blobId); return 2 === count($blobId) && is_numeric($blobId[0]) && is_numeric($blobId[1]); } /** * When having a record like 'Actions_ActionUrls_chunk_0_99" it will return the raw recordName 'Actions_ActionUrls'. * * @param string $recordName * @return string */ public function getRecordNameWithoutChunkAppendix($recordName) { if (!$this->isRecordNameAChunk($recordName)) { return $recordName; } $posAppendix = $this->getStartPosOfChunkAppendix($recordName); if (false === $posAppendix) { return $recordName; } return substr($recordName, 0, $posAppendix); } /** * Returns the string that is appended to the original record name. This appendix identifes a record name is a * chunk. * @return string */ public function getAppendix() { return '_' . self::ARCHIVE_APPENDIX_SUBTABLES . '_'; } private function getStartPosOfChunkAppendix($recordName) { return strpos($recordName, $this->getAppendix()); } private function getEndPosOfChunkAppendix($recordName) { $pos = strpos($recordName, $this->getAppendix()); if ($pos === false) { return false; } return $pos + strlen($this->getAppendix()); } }