doctrine / couchdb-client

CouchDB Client library
MIT License
122 stars 68 forks source link

Add getConnection(). Add getChangesAsStream() and transferChangedDocuments() with tests. Add MultipartParserAndSender with tests. Make some PSR-2 corrections. Remove support for PHP 5.3. #45

Closed Abhishek-17 closed 9 years ago

Abhishek-17 commented 9 years ago

Hi. I am working on a project under Google's summer of code program for Drupal which involves writing a PHP based replicator. This is the second set of changes enchancing the client in general and also for supporting the PHP implementation of the CouchDB replication protocol. The first set of changes have already been merged and can be seen by following pull/42 link.

The changes mainly now allow the client to read data from source CouchDb client in chunks and stream it to the target CouchDb client. This is mainly useful when the docs to be replicated have large attachments exceeding the space available locally on the drive. To do this I have added the ability in the StreamClient and the SocketClient to return the connection resource.

Let's go through the changes file by file:

  1. CouchDBClient.php
    1. Add transferChangedDocuments(). This method transfers the missing revisions from the current source database to the target database.
    2. Add getChangesAsStream(). This method returns the resource from which changes feed can be read continuously.
  2. AbstractHTTPClient.php
    1. Add getOptions(). It's the getter for connection options.
  3. Client.php
    1. Add getConnection(). This method is expected to return a connection resource which can be used to read or write in small chunks.
  4. MultipartParserAndSender.php This file has all the logic needed to transfer the multipart data between two connection resources. It reads the multipart stream, parses it, and streams it to the target. For details see the inline documentations.
  5. SocketClient.php
    1. The code has been modularized.
    2. Add getConnection(). This method returns the connection resource after setting up the connection. This resource can be used for reading or writing data in chunks. This must be done without much delay as the connection might get closed.
  6. StreamClient.php
    1. The code has been modularized.
    2. Add getConnection(). This method returns the connection resource after setting up the connection. This resource can be used only for reading data in chunks.
  7. CouchDBClientTest.php
    1. Add testTransferChangedDocuments(). This is the test for transferChangedDocuments().
    2. Add testGetChangesAsStream(). This is the test for getChangesAsStream().
  8. Other Changes
    1. The inline comments have been made to lie within the 80 chars on a line limit.
    2. The newly added or modified code has been made to follow PSR-2 conventions. This mostly includes removal of spaces betweent the opening/closing parentheses and the first/last parameter and the placement of the curly brace on the same line for if, for, while etc.
beberlei commented 9 years ago

Overall very good quality PR, but it needs a bit more tests as mentioned in inline comments.

Abhishek-17 commented 9 years ago

Incorporating the above feedback, the following major changes have been made:

  1. MultipartParserAndSenderTest.php has been added which has tests for the MultipartParserAndSender.
  2. getConnection() has been implemented in the LoggingClient.
  3. PHP version in composer.json has been changed to >=5.4.
  4. Support for filtered changes feed has been removed from the getChangesAsStream() method. It was not useful as the response in this case is not a continuous stream but a JSON after which the connection gets closed. For filtered feed use the getChanges() method.
  5. Some inline comments and PHPDocs have been updated.