← All changes
|
class/Common/Importer/File/AbstractIndexedFile.php
+30
-6
2.7.1
→
2.15.0
View file →
| @@ -92,9 +92,9 @@ | ||
| 92 | 92 | * @param int $record |
| 93 | 93 | * |
| 94 | 94 | * @return array |
| 95 | 95 | */ |
| 96 | - protected function getIndex($record) | |
| 96 | + public function getIndex($record) | |
| 97 | 97 | { |
| 98 | 98 | if (!$this->loadIndex()) { |
| 99 | 99 | $this->generateIndex(); |
| 100 | 100 | $this->storeIndexes(); |
| @@ -111,9 +111,9 @@ | ||
| 111 | 111 | * @param int $end |
| 112 | 112 | * |
| 113 | 113 | * @internal param $index |
| 114 | 114 | */ |
| 115 | - protected function setIndex($record, $start, $end) | |
| 115 | + public function setIndex($record, $start, $end) | |
| 116 | 116 | { |
| 117 | 117 | if (!$this->loadIndex()) { |
| 118 | 118 | $this->generateIndex(); |
| 119 | 119 | $this->storeIndexes(); |
| @@ -129,9 +129,9 @@ | ||
| 129 | 129 | * Load index from cache |
| 130 | 130 | * |
| 131 | 131 | * @return bool |
| 132 | 132 | */ |
| 133 | - protected function loadIndex() | |
| 133 | + public function loadIndex() | |
| 134 | 134 | { |
| 135 | 135 | if ($this->loaded) { |
| 136 | 136 | return true; |
| 137 | 137 | } |
| @@ -145,8 +145,16 @@ | ||
| 145 | 145 | return false; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
| 149 | + * Force the next index access to reload/regenerate for the current key. | |
| 150 | + */ | |
| 151 | + public function resetIndexState() | |
| 152 | + { | |
| 153 | + $this->loaded = false; | |
| 154 | + } | |
| 155 | + | |
| 156 | + /** | |
| 149 | 157 | * Generate file position index. |
| 150 | 158 | * |
| 151 | 159 | * @return mixed |
| 152 | 160 | */ |
| @@ -194,9 +202,9 @@ | ||
| 194 | 202 | |
| 195 | 203 | return false; |
| 196 | 204 | } |
| 197 | 205 | |
| 198 | - protected function storeIndexes() | |
| 206 | + public function storeIndexes() | |
| 199 | 207 | { |
| 200 | 208 | if (null === $this->config) { |
| 201 | 209 | return false; |
| 202 | 210 | } |
| @@ -203,9 +211,9 @@ | ||
| 203 | 211 | |
| 204 | 212 | return $this->config->storeIndexes($this->getFileIndexKey()); |
| 205 | 213 | } |
| 206 | 214 | |
| 207 | - private function readIndexes() | |
| 215 | + public function readIndexes() | |
| 208 | 216 | { |
| 209 | 217 | if (null === $this->config) { |
| 210 | 218 | return false; |
| 211 | 219 | } |
| @@ -214,9 +222,9 @@ | ||
| 214 | 222 | |
| 215 | 223 | // return $this->index = $this->config->get( $this->getFileIndexKey() ); |
| 216 | 224 | } |
| 217 | 225 | |
| 218 | - protected function getFileIndexKey() | |
| 226 | + public function getFileIndexKey() | |
| 219 | 227 | { |
| 220 | 228 | return 'file_index'; |
| 221 | 229 | } |
| 222 | 230 | |
| @@ -222,6 +230,22 @@ | ||
| 222 | 230 | |
| 223 | 231 | public function processing($processing = false) |
| 224 | 232 | { |
| 225 | 233 | $this->is_processing = true; |
| 234 | + } | |
| 235 | + | |
| 236 | + /** | |
| 237 | + * Read file size from handle and reset pointer back to current position | |
| 238 | + * | |
| 239 | + * @param resource $handle | |
| 240 | + * @return void | |
| 241 | + */ | |
| 242 | + public function get_file_size($handle) | |
| 243 | + { | |
| 244 | + $current = ftell($handle); | |
| 245 | + fseek($handle, 0, SEEK_END); | |
| 246 | + $size = ftell($handle); | |
| 247 | + fseek($handle, $current); | |
| 248 | + | |
| 249 | + return $size; | |
| 226 | 250 | } |
| 227 | 251 | } |