Пример #1
0
 /**
  * Perform the actual replacement
  *
  * @param Tx_Smoothmigration_Domain_Model_Issue $issue
  * @param object $locationInfo
  *
  * @return boolean
  */
 protected function performReplacement(Tx_Smoothmigration_Domain_Model_Issue $issue, $locationInfo)
 {
     $search = trim($locationInfo->getMatchedString());
     $replacement = trim($search, ')') . ', \'' . $issue->getExtension() . '\')';
     $this->messageService->message($locationInfo->getFilePath() . ' line: ' . $locationInfo->getLineNumber() . LF . 'Replacing [' . $search . '] =>' . ' [' . $replacement . ']');
     if ($issue->getMigrationStatus() != 0) {
         $this->messageService->successMessage('already migrated', TRUE);
         return;
     }
     if (!file_exists($locationInfo->getFilePath())) {
         $issue->setMigrationStatus(Tx_Smoothmigration_Domain_Interface_Migration::ERROR_FILE_NOT_FOUND);
         $this->messageService->errorMessage('Error, file not found', TRUE);
         return;
     }
     if (!is_writable($locationInfo->getFilePath())) {
         $issue->setMigrationStatus(Tx_Smoothmigration_Domain_Interface_Migration::ERROR_FILE_NOT_WRITABLE);
         $this->messageService->errorMessage('Error, file not writable', TRUE);
         return;
     }
     $fileObject = new SplFileObject($locationInfo->getFilePath());
     $newFileContent = '';
     foreach ($fileObject as $lineNumber => $lineContent) {
         if ($lineNumber + 1 != $locationInfo->getLineNumber()) {
             $newFileContent .= $lineContent;
         } else {
             $newLineContent = str_replace($search, $replacement, $lineContent);
             if (!strstr($newLineContent, $replacement)) {
                 $issue->setMigrationStatus(Tx_Smoothmigration_Domain_Interface_Migration::ERROR_FILE_NOT_CHANGED);
                 $this->messageService->errorMessage($this->ll('migrationsstatus.4'), TRUE);
                 return;
             }
             $newFileContent .= $newLineContent;
         }
     }
     file_put_contents($locationInfo->getFilePath(), $newFileContent);
     $issue->setMigrationStatus(Tx_Smoothmigration_Domain_Interface_Migration::SUCCESS);
     $this->messageService->successMessage('Succes' . LF, TRUE);
 }