-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from talis/ent-71-regenerate-composites
ENT-71: regenerate composites without clearing collection first
- Loading branch information
Showing
21 changed files
with
1,574 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# This file is for unifying the coding style for different editors and IDEs | ||
# editorconfig.org | ||
|
||
# PHP PSR-2 Coding Standards | ||
# http://www.php-fig.org/psr/psr-2/ | ||
|
||
root = true | ||
|
||
[*.php] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
indent_style = space | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.idea | ||
composer.phar | ||
composer.lock | ||
output | ||
vendor | ||
tags | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
mongo: | ||
image: mongo/2.6.12:latest | ||
ports: | ||
- "27017:27017" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace Tripod\Mongo; | ||
|
||
use \MongoDB\BSON\ObjectId; | ||
|
||
class JobGroup | ||
{ | ||
private $id; | ||
private $collection; | ||
private $storeName; | ||
|
||
/** | ||
* Constructor method | ||
* @param string $storeName Tripod store (database) name | ||
* @param string|ObjectId $groupId Optional tracking ID, will assign a new one if omitted | ||
*/ | ||
public function __construct($storeName, $groupId = null) | ||
{ | ||
$this->storeName = $storeName; | ||
if (!$groupId) { | ||
$groupId = new ObjectId(); | ||
} elseif (!$groupId instanceof ObjectId) { | ||
$groupId = new ObjectId($groupId); | ||
} | ||
$this->id = $groupId; | ||
} | ||
|
||
/** | ||
* Update the number of jobs | ||
* | ||
* @param integer $count Number of jobs in group | ||
* @return void | ||
*/ | ||
public function setJobCount($count) | ||
{ | ||
$this->getMongoCollection()->updateOne( | ||
['_id' => $this->getId()], | ||
['$set' => ['count' => $count]], | ||
['upsert' => true] | ||
); | ||
} | ||
|
||
/** | ||
* Update the number of jobs by $inc. To decrement, use a negative integer | ||
* | ||
* @param integer $inc Number to increment or decrement by | ||
* @return integer Updated job count | ||
*/ | ||
public function incrementJobCount($inc = 1) | ||
{ | ||
$updateResult = $this->getMongoCollection()->findOneAndUpdate( | ||
['_id' => $this->getId()], | ||
['$inc' => ['count' => $inc]], | ||
['upsert' => true, 'returnDocument' => \MongoDB\Operation\FindOneAndUpdate::RETURN_DOCUMENT_AFTER] | ||
); | ||
if (\is_array($updateResult)) { | ||
return $updateResult['count']; | ||
} elseif (isset($updateResult->count)) { | ||
return $updateResult->count; | ||
} | ||
} | ||
|
||
/** | ||
* @return ObjectId | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* For mocking | ||
* | ||
* @return \MongoDB\Collection | ||
*/ | ||
protected function getMongoCollection() | ||
{ | ||
if (!isset($this->collection)) { | ||
$config = Config::getInstance(); | ||
|
||
$this->collection = $config->getCollectionForJobGroups($this->storeName); | ||
} | ||
return $this->collection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.