Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-45412

Mongo is dead, long live MongoClient

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • 2.5.6, 2.6.3
    • 2.5.5, 2.6.2, 2.7
    • Caching
    • MOODLE_25_STABLE, MOODLE_26_STABLE, MOODLE_27_STABLE
    • MOODLE_25_STABLE, MOODLE_26_STABLE
    • 45412-27
    • Hide
      1. Install Mongo (< 1.3) if you havn't already and make sure it is started.
      2. Add the following to your config.php: define('TEST_CACHESTORE_MONGODB_TESTSERVER', 'mongodb://127.0.0.1:27017');
      3. Run vendor/bin/phpunit cache/stores/mongodb/tests/mongodb_test.php
      4. Ensure all tests pass and that you don't get any warnings.

      For extra credit":

      1. Downgrade you Mongo PHP extension to 1.2 and rerun the test suite.
      2. Ensure you still get passes and that you don't get warning.
      3. Browse to the form to add a mongo instance and check you see a notice about upgrading your mongo ext.
      Show
      Install Mongo (< 1.3) if you havn't already and make sure it is started. Add the following to your config.php: define('TEST_CACHESTORE_MONGODB_TESTSERVER', 'mongodb://127.0.0.1:27017'); Run vendor/bin/phpunit cache/stores/mongodb/tests/mongodb_test.php Ensure all tests pass and that you don't get any warnings. For extra credit": Downgrade you Mongo PHP extension to 1.2 and rerun the test suite. Ensure you still get passes and that you don't get warning. Browse to the form to add a mongo instance and check you see a notice about upgrading your mongo ext.

      Trying to get 100% unit test completion here before Moodle 2.7, it was detected that we are using some deprecated stuff in the mongodb cache store.

      Note that those deprecated uses continue working and they are not a problem for normal use, but they are a problem for getting unit tests passing (because of the PHP Warning they produce).

      Looking for information, it seems the change happened in 2012... so perhaps it would be the time to change our store too:

      http://derickrethans.nl/mongoclient.html

      Just for reference, and in order to pass unit tests, I've applied here these quick changes (sure there are more, just to show the minimum I needed to get them passing without any warning):

      index cdf764f..f7acf8c 100644
      --- a/cache/stores/mongodb/lib.php
      +++ b/cache/stores/mongodb/lib.php
      @@ -141,7 +141,7 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
               }
       
               try {
      -            $this->connection = new Mongo($this->server, $this->options);
      +            $this->connection = new MongoClient($this->server, $this->options);
                   $this->isready = true;
               } catch (MongoConnectionException $e) {
                   // We only want to catch MongoConnectionExceptions here.
      @@ -303,7 +303,6 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
               $record['data'] = serialize($data);
               $options = array(
                   'upsert' => true,
      -            'safe' => $this->usesafe,
                   'w' => $this->usesafe ? 1 : 0
               );
               $this->delete($key);
      @@ -356,7 +355,6 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
               }
               $options = array(
                   'justOne' => false,
      -            'safe' => $this->usesafe,
                   'w' => $this->usesafe ? 1 : 0
               );
               $result = $this->collection->remove($criteria, $options);
      @@ -483,7 +481,7 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
                   $connection = $this->connection;
               } else {
                   try {
      -               $connection = new Mongo($this->server, $this->options);
      +               $connection = new MongoClient($this->server, $this->options);
                   } catch (MongoConnectionException $e) {
                       // We only want to catch MongoConnectionExceptions here.
                       // If the server cannot be connected to we cannot clean it.
      

      Basically Mongo() goes to MongoClient() and the 'safe' option is out (with 'w' getting the baton/changed its default).

      Ciao

            samhemelryk Sam Hemelryk
            stronk7 Eloy Lafuente (stronk7)
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Damyon Wiese Damyon Wiese
            Damyon Wiese Damyon Wiese
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.