If you don't rewind + update + flush header, the current seek position shows to
[core.git] / inc / classes / main / class_BaseFrameworkSystem.php
index 161710f552f119e0faa8ceefb0c3288cfa5e91fe..be6499dc3f5d7e7a0cfa9beaff4199b913e5bdf7 100644 (file)
@@ -3054,17 +3054,37 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Simple flush file header which will create it.
                $this->flushFileHeader();
 
+               // Seek to beginning of file
+               $this->getIteratorInstance()->rewind();
+
+               // And update seek position ...
+               $this->updateSeekPosition();
+
+               // ... to write it back into the file
+               $this->flushFileHeader();
+
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!!', __METHOD__, __LINE__));
        }
 
+       /**
+        * Seeks to old position
+        *
+        * @return      void
+        */
+       protected function seekToOldPosition () {
+               // Seek to currently ("old") saved position
+               $this->getIteratorInstance()->seek($this->getSeekPosition());
+       }
+
        /**
         * Writes data at given position
         *
         * @param       $seekPosition   Seek position
         * @param       $data                   Data to be written
+        * @param       $flushHeader    Whether to flush the header (default: flush)
         * @return      void
         */
-       protected function writeData ($seekPosition, $data) {
+       protected function writeData ($seekPosition, $data, $flushHeader = TRUE) {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] seekPosition=%s,data()=%s - CALLED!', __METHOD__, __LINE__, $seekPosition, strlen($data)));
 
                // Write data at given position
@@ -3073,8 +3093,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Update seek position
                $this->updateSeekPosition();
 
-               // Flush header
-               $this->flushFileHeader();
+               // Flush the header?
+               if ($flushHeader === TRUE) {
+                       // Flush header
+                       $this->flushFileHeader();
+               } // END - if
 
                // Seek to old position
                $this->seekToOldPosition();