Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0.0BETA2
    • Component/s: Persister
    • Labels:
      None
    • Environment:
      Mongodb 1.6 (64-bit + Google V8)

      Description

      When I save a document and then read it again updated the document with the initial values.

      The following log output when saving Doctrine:

      Array
      (
          [storing] => 1
          [file] => /app/tests/cases/models/asset/test.swf
          [document] => Array
              (
                  [filename] => a3f06b4b882ee28ee8d8c7a5e6ab67e6.swf
                  [php] => ass
              )
      
          [class] => Documents\Assets\Asset
          [db] => test
          [collection] => assets_files
      )
      
      Array
      (
          [batchInsert] => 1
          [num] => 1
          [data] => Array
              (
                  [00000000341a62a40000000001574585] => Array
                      (
                          [cS] => 3
                          [rS] => 3
                          [co] => 0
                          [ca] => 0
                          [lvl] => 0
                          [nb] => 0
                          [sex] => 0
                          [na] => Building01
                          [typ] => building
                          [as] => Array
                              (
                                  [$ref] => assets_files
                                  [$id] => MongoId Object
                                      (
                                      )
      
                                  [$db] => test
                              )
      
                      )
      
              )
      
          [class] => Documents\Assets\MapAsset
          [db] => test
          [collection] => map_assets
      )
      

      Then read:

      Array
      (
          [findOne] => 1
          [query] => Array
              (
                  [_id] => MongoId Object
                      (
                      )
      
              )
      
          [fields] => Array
              (
              )
      
          [class] => Documents\Assets\MapAsset
          [db] => test
          [collection] => map_assets
      )
      

      Then check for updates Document:

      $this->dm->getUnitOfWork()->computeChangeSets();
      $update = $this->dm->getUnitOfWork()->getDocumentPersister('Documents\Assets\MapAsset')->prepareUpdateData($mapAsset);
      print_r($update);
      
      Array
      (
          [$set] => Array
              (
                  [cS] => 3
                  [rS] => 3
                  [co] => 0
                  [ca] => 0
                  [lvl] => 0
                  [nb] => 0
                  [sex] => 0
                  [na] => Building01
                  [typ] => building
                  [as] => Array
                      (
                          [$ref] => assets_files
                          [$id] => MongoId Object
                              (
                              )
      
                          [$db] => test
                      )
      
              )
      
      )
      

      Why is there an update even though it set the initial values? In Mongo are the values set correctly!

      Then I run a flush:

      Array
      (
          [update] => 1
          [criteria] => Array
              (
                  [_id] => MongoId Object
                      (
                      )
      
              )
      
          [newObj] => Array
              (
                  [$set] => Array
                      (
                          [uploadDate] => 0.63800000 1283421657
                          [length] => 4222
                          [chunkSize] => 262144
                          [md5] => 2af70cb102026bde0cf9f181780b642c
                      )
      
              )
      
          [options] => Array
              (
              )
      
          [class] => Documents\Assets\Asset
          [db] => test
          [collection] => assets_files
      )
      
      Array
      (
          [update] => 1
          [criteria] => Array
              (
                  [_id] => MongoId Object
                      (
                      )
      
              )
      
          [newObj] => Array
              (
                  [$set] => Array
                      (
                          [cS] => 3
                          [rS] => 3
                          [co] => 0
                          [ca] => 0
                          [lvl] => 0
                          [nb] => 0
                          [sex] => 0
                          [na] => Building01
                          [typ] => building
                          [as] => Array
                              (
                                  [$ref] => assets_files
                                  [$id] => MongoId Object
                                      (
                                      )
      
                                  [$db] => test
                              )
      
                      )
      
              )
      
          [options] => Array
              (
              )
      
          [class] => Documents\Assets\MapAsset
          [db] => test
          [collection] => map_assets
      )
      

      1st Doctrine update GridFS file and destroyed it! Wrong value for uploadDate and the file can then be displayed in the browser no longer!

      2nd Why did he updatet The Document with the same values that are already there in Mongo and the initial values are?

      Here is my test code:

      $asset = APP_TEST_CASES . DS . 'models' . DS . 'asset' . DS . 'test.swf';
      $assetInfo = pathinfo($asset);
      $assetName =  md5($assetInfo['basename'] . time() . mt_rand()) . '.' . $assetInfo['extension'];
      $assetFile = new Documents\Assets\Asset($asset, $assetName);
      
      $cSpan = 3;
      $rSpan = 3;
      $mapAsset = new Documents\Assets\MapAsset('Building01', 'building', $cSpan, $rSpan, null, $assetFile);
      $this->assertEqual($mapAsset->getColumnSpan(), $cSpan);
      $this->assertEqual($mapAsset->getRowSpan(), $rSpan);
      $this->assertEqual($mapAsset->getSpans(), array('columnSpan' => $cSpan, 'rowSpan' => $rSpan));
      
      $this->dm->persist($mapAsset);
      $this->dm->flush();
      $this->dm->refresh($mapAsset);
      
      $this->dm->getUnitOfWork()->computeChangeSets();
      $update = $this->dm->getUnitOfWork()->getDocumentPersister('Documents\Assets\MapAsset')->prepareUpdateData($mapAsset);
      debug($update);
      $this->dm->flush();
      

      Here is my test Documents:

      namespace Documents\Assets;
      
      /**
       * @Document(collection="assets_files")
       */
      class Asset {
      	/**
      	 * @Id
      	 * @var string
      	 */
      	protected $_id;
      	/**
      	 * @File
      	 */
      	protected $_file;
      	/**
      	 * @String(name="filename")
      	 */
      	protected $_filename;
      	/**
      	 * @Field(name="uploadDate")
      	 * @var int
      	 */
      	protected $_uploadDate;
      	/**
      	 * @Field(name="length")
      	 * @var int
      	 */
      	protected $_length;
      	/**
      	 * @Field(name="chunkSize")
      	 * @var int
      	 */
      	protected $_chunkSize;
      	/**
      	 * @Field(name="md5")
      	 * @var string
      	 */
      	protected $_md5;
      	/**
      	 * @Field(name="contentType")
      	 * @var string
      	 */
      	protected $_contentType;
      	/**
      	 * @Field(name="metadata")
      	 * @var string
      	 */
      	protected $_metadata;
      
      	public function __construct($file, $filename = null) {
      		$this->_file = $file;
      		$this->_filename = $filename;
      	}
      	
      	// ..
      }
      
      namespace Documents\Assets;
      
      /**
       * @Document(collection="map_assets")
       */
      class MapAsset {
      	/**
      	 * @Id
      	 * @var string
      	 */
      	protected $_id;
      
      	/**
      	 * @ReferenceOne(
      	 *	targetDocument="Documents\Assets\Asset",
      	 *	name="as",
      	 *	cascade={"persist", "remove"}
      	 *	)
      	 * @var Documents\Assets\Asset
      	 */
      	protected $_asset;
      
      	// ..
      }
      

        Issue Links

          Activity

          Hide
          Bulat Shakirzyanov added a comment -

          should be fixed here http://github.com/doctrine/mongodb-odm/tree/MODM-70, Jon please review.
          The issue was cause due to the fact, that after hydration in UnitOfWork::getOrCreateDocument() we used the resultset from mongo as originalDocumentData, which in case field names were different from document properties led to wrong changeset calculation

          Show
          Bulat Shakirzyanov added a comment - should be fixed here http://github.com/doctrine/mongodb-odm/tree/MODM-70 , Jon please review. The issue was cause due to the fact, that after hydration in UnitOfWork::getOrCreateDocument() we used the resultset from mongo as originalDocumentData, which in case field names were different from document properties led to wrong changeset calculation
          Hide
          Thomas Adam added a comment -

          Fantastic! it works. Many many thanks

          Show
          Thomas Adam added a comment - Fantastic! it works. Many many thanks
          Hide
          Sebastian Hoitz added a comment -

          I can also say that it works. This should be resolved.

          Show
          Sebastian Hoitz added a comment - I can also say that it works. This should be resolved.
          Hide
          Thomas Adam added a comment -

          When it is added into the master branch?

          Show
          Thomas Adam added a comment - When it is added into the master branch?
          Hide
          Jonathan H. Wage added a comment -

          This is fixed now due to some other refactoring we did. Committed test here https://github.com/doctrine/mongodb-odm/commit/bfe54c52ac242181392c6c8f9af04c9885b53db8 and it is passing. Thanks!

          Show
          Jonathan H. Wage added a comment - This is fixed now due to some other refactoring we did. Committed test here https://github.com/doctrine/mongodb-odm/commit/bfe54c52ac242181392c6c8f9af04c9885b53db8 and it is passing. Thanks!

            People

            • Assignee:
              Bulat Shakirzyanov
              Reporter:
              Thomas Adam
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: