Просмотр исходного кода

Implement MongoDB::repair method

Andreas Braun 10 лет назад
Родитель
Сommit
7e2eb3181c
3 измененных файлов с 12 добавлено и 3 удалено
  1. 0 2
      README.md
  2. 7 1
      lib/Mongo/MongoDB.php
  3. 5 0
      tests/Alcaeus/MongoDbAdapter/MongoDBTest.php

+ 0 - 2
README.md

@@ -86,8 +86,6 @@ return `0` as connection ID.
  and [listCollections](https://php.net/manual/en/mongodb.listcollections.php)
  methods is ignored. These methods do not return information about system
  collections.
- - The [repair](https://secure.php.net/manual/en/mongodb.repair.php)
- method is not yet implemented.
 
 ## MongoCollection
 

+ 7 - 1
lib/Mongo/MongoDB.php

@@ -242,7 +242,13 @@ class MongoDB
      */
     public function repair($preserve_cloned_files = FALSE, $backup_original_files = FALSE)
     {
-        $this->notImplemented();
+        $command = [
+            'repairDatabase' => 1,
+            'preserveClonedFilesOnFailure' => $preserve_cloned_files,
+            'backupOriginalFiles' => $backup_original_files,
+        ];
+
+        return $this->command($command);
     }
 
     /**

+ 5 - 0
tests/Alcaeus/MongoDbAdapter/MongoDBTest.php

@@ -308,4 +308,9 @@ class MongoDBTest extends TestCase
         ];
         $this->assertSame($expected, $this->getDatabase()->dropCollection('test'));
     }
+
+    public function testRepair()
+    {
+        $this->assertSame(['ok' => 1.0], $this->getDatabase()->repair());
+    }
 }