Skip to content

Commit

Permalink
Allow for shipping of non eloquent models
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Chawla committed Feb 9, 2024
1 parent e3975db commit ccd3e94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/DataShipper.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function pushMany(string $className, array|Collection $changes, $identifi
* @return void
* @throws \Exception
*/
public function push(string $className, array|Collection $changes, $identifier, string $mode = Package::MODE_UPDATE): void {
public function push(string $className, array|Collection $changes, mixed $identifier, string $mode = Package::MODE_UPDATE): void {
if (!in_array(HasDataSubscribers::class, class_uses_recursive($className))) {
throw new \Exception("Provided model does not use the HasDataSubscribers trait");
}
Expand Down
10 changes: 4 additions & 6 deletions src/ShipmentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ShipmentRepository {
* @var array
*/
public array $keys = [
'id', 'uuid', 'table', 'payload', 'class_name', 'mode'
'id', 'uuid', 'payload', 'class_name', 'mode'
];

public function __construct(RedisFactory $redis, int $minutesUntilShipment = 5, int $maxShipmentLength = 10) {
Expand Down Expand Up @@ -196,11 +196,10 @@ public function updateShipmentManifest($pipe, string $key, bool $now = false): v
* Push a package into a shipment container
*
* @param PackageInterface|PackageInterface[] $packages
* @param Model $model
* @param object $model
* @return void
*/
public function push(array|PackageInterface $packages, Model $model): void {
$table = $model->getTable();
public function push(array|PackageInterface $packages, object $model): void {
$className = get_class($model);

if (!(is_array($packages))) {
Expand All @@ -215,7 +214,7 @@ public function push(array|PackageInterface $packages, Model $model): void {

$lock->release();

$this->connection()->pipeline(function ($pipe) use ($packages, $table, $className, $currentShipmentSize) {
$this->connection()->pipeline(function ($pipe) use ($packages, $className, $currentShipmentSize) {

if ($currentShipmentSize === count($packages) && $currentShipmentSize < $this->maxShipmentLength) {
// Record the shipment and
Expand All @@ -231,7 +230,6 @@ public function push(array|PackageInterface $packages, Model $model): void {
$pipe->hmset($package->uuid(), [
'id' => $package->id(),
'uuid' => $package->uuid(),
'table' => $table,
'class_name' => $package->className(),
'payload' => $package->pack(),
'mode' => $package->mode(),
Expand Down

0 comments on commit ccd3e94

Please sign in to comment.