src/Charcoal/Object/ObjectSchedule.php
public function process(
        callable $callback = null,
        callable $successCallback = null,
        callable $failureCallback = null
    ) {

        if ($this->processed() === true) {
            // Do not process twice, ever.
            return null;
        }

        if ($this->targetType() === null) {
            $this->logger->error('Can not process object schedule: no object type defined.');
            return false;
        }

        if ($this->targetId() === null) {
            $this->logger->error(sprintf(
                'Can not process object schedule: no object "%s" ID defined.',
                $this->targetType()
            ));
            return false;
        }

        if (empty($this->dataDiff())) {
            $this->logger->error('Can not process object schedule: no changes (diff) defined.');
            return false;
        }

        $obj = $this->modelFactory()->create($this->targetType());
        $obj->load($this->targetId());
        if (!$obj->id()) {
            $this->logger->error(sprintf(
                'Can not load "%s" object %s',
                $this->targetType(),
                $this->targetId()
            ));
        }
        $obj->setData($this->dataDiff());
        $update = $obj->update(array_keys($this->dataDiff()));

        if ($update) {
            $this->setProcessed(true);
            $this->setProcessedDate('now');
            $this->update(['processed', 'processed_date']);

            if ($successCallback !== null) {
                $successCallback($this);
            }
        } else {
            if ($failureCallback !== null) {
                $failureCallback($this);
            }
        }

        if ($callback !== null) {
            $callback($this);
        }

        return $update;
    }
public function process(
        callable $callback = null,
        callable $successCallback = null,
        callable $failureCallback = null
    ) {

        if ($this->processed() === true) {
            // Do not process twice, ever.
            return null;
        }

        if ($this->targetType() === null) {
            $this->logger->error('Can not process object schedule: no object type defined.');
            return false;
        }

        if ($this->targetId() === null) {
            $this->logger->error(sprintf(
                'Can not process object schedule: no object "%s" ID defined.',
                $this->targetType()
            ));
            return false;
        }

        if (empty($this->dataDiff())) {
            $this->logger->error('Can not process object schedule: no changes (diff) defined.');
            return false;
        }

        $obj = $this->modelFactory()->create($this->targetType());
        $obj->load($this->targetId());
        if (!$obj->id()) {
            $this->logger->error(sprintf(
                'Can not load "%s" object %s',
                $this->targetType(),
                $this->targetId()
            ));
        }
        $obj->setData($this->dataDiff());
        $update = $obj->update(array_keys($this->dataDiff()));

        if ($update) {
            $this->setProcessed(true);
            $this->setProcessedDate('now');
            $this->update(['processed', 'processed_date']);

            if ($successCallback !== null) {
                $successCallback($this);
            }
        } else {
            if ($failureCallback !== null) {
                $failureCallback($this);
            }
        }

        if ($callback !== null) {
            $callback($this);
        }

        return $update;
    }
Process the item.

@param  callable $callback        An optional callback routine executed after the item is processed.
@param  callable $successCallback An optional callback routine executed when the item is resolved.
@param  callable $failureCallback An optional callback routine executed when the item is rejected.
@return boolean|null  Success / Failure, or null in case of a skipped item.