Schedules a document for dirty-checking at commit-time.

@internal
434306
public function scheduleForSynchronization(object $document) : void
    {
        $class                                                                       = $this->dm->getClassMetadata(get_class($document));
        $this->scheduledForSynchronization[$class->name][spl_object_hash($document)] = $document;
    }
358633
public function forceCheckIn()
    {
        $db = Database::connection();
        $q = 'update Pages set cIsCheckedOut = 0, cCheckedOutUID = null, cCheckedOutDatetime = null, cCheckedOutDatetimeLastEdit = null where cID = ?';
        $db->executeQuery($q, [$this->cID]);
    }
477913
protected function manageStartedEvents(): void
    {
        while ($this->schedules) {
            foreach ($this->schedules as $scheduleKey => $schedule) {
                $events = $schedule->events();
                // 10% chance that refresh will be called
                $refreshLocks = (\mt_rand(1, 100) <= 10);

                /** @var Event $event */
                foreach ($events as $eventKey => $event) {
                    if ($refreshLocks) {
                        $event->refreshLock();
                    }

                    $proc = $event->getProcess();
                    if ($proc->isRunning()) {
                        continue;
                    }

                    $runStatus = '';

                    if ($proc->isSuccessful()) {
                        $this->consoleLogger
                            ->debug("Invoke Event's ping after.");
                        $this->pingAfter($event);

                        $runStatus = '<info>success</info>';

                        $event->outputStream .= $event->wholeOutput();
                        $event->outputStream .= $this->invoke($event->afterCallbacks());

                        $this->handleOutput($event);
                    } else {
                        $runStatus = '<error>fail</error>';
                        // Calling registered error callbacks with an instance of $event as argument
                        $this->invoke($schedule->errorCallbacks(), [$event]);
                        $this->handleError($event);
                    }

                    $id = $event->description ?: $event->getId();

                    $this->consoleLogger
                        ->debug("Task <info>${id}</info> status: {$runStatus}.");

                    // Dismiss the event if it's finished
                    $schedule->dismissEvent($eventKey);
                }

                // If there's no event left for the Schedule instance,
                // run the schedule's after-callbacks and remove
                // the Schedule from list of active schedules.                                                                                                                           zzzwwscxqqqAAAQ11
                if (!\count($schedule->events())) {
                    $this->consoleLogger
                        ->debug("Invoke Schedule's ping after.");

                    $this->pingAfter($schedule);
                    $this->invoke($schedule->afterCallbacks());
                    unset($this->schedules[$scheduleKey]);
                }
            }

            \usleep(250000);
        }
    }
290700
public function onBeforeWrite()
    {
        parent::onBeforeWrite();

        // only operate on staging content for this extension; otherwise, you
        // need to publish the page to be able to set a 'future' publish...
        // while the same could be said for the unpublish, the 'publish' state
        // is the one that must be avoided so we allow setting the 'unpublish'
        // date for as-yet-not-published content.
        if (Versioned::get_stage() === Versioned::LIVE) {
            return;
        }

        /*
         * Without checking if there's actually a workflow in effect, simply saving
         * as draft, would clear the Scheduled Publish & Unpublish date fields, which we obviously
         * don't want during a workflow: These date fields should be treated as a content
         * change that also requires approval (where such an approval step exists).
         *
         * - Check to see if we've got 'desired' publish/unpublish date(s).
         * - Check if there's a workflow attached to this content
         * - Reset values if it's safe to do so
         */
        if (!$this->getIsWorkflowInEffect()) {
            $resetPublishOnDate = $this->owner->DesiredPublishDate && $this->owner->PublishOnDate;
            if ($resetPublishOnDate) {
                $this->owner->PublishOnDate = null;
            }

            $resetUnPublishOnDate = $this->owner->DesiredUnPublishDate && $this->owner->UnPublishOnDate;
            if ($resetUnPublishOnDate) {
                $this->owner->UnPublishOnDate = null;
            }
        }

        // Jobs can only be queued for records that already exist
        if (!$this->owner->ID) {
            return;
        }

        // Check requested dates of publish / unpublish, and whether the page should have already been unpublished
        $now = DBDatetime::now()->getTimestamp();
        $publishTime = $this->owner->dbObject('PublishOnDate')->getTimestamp();
        $unPublishTime = $this->owner->dbObject('UnPublishOnDate')->getTimestamp();

        // We should have a publish job if:
        // if no unpublish or publish time, then the Workflow Publish Action will publish without a job
        if ((!$unPublishTime && $publishTime) // the unpublish date is not set
            || (
                // unpublish date has not passed
                $unPublishTime > $now
                // publish date not set or happens before unpublish date
                && ($publishTime && ($publishTime < $unPublishTime))
            )
        ) {
            // Trigger time immediately if passed
            $this->ensurePublishJob($publishTime < $now ? null : $publishTime);
        } else {
            $this->clearPublishJob();
        }

        // We should have an unpublish job if:
        if ($unPublishTime // we have an unpublish date
            &&
            $publishTime < $unPublishTime // publish date is before to unpublish date
        ) {
            // Trigger time immediately if passed
            $this->ensureUnPublishJob($unPublishTime < $now ? null : $unPublishTime);
        } else {
            $this->clearUnPublishJob();
        }
    }
1031498
public function index($document, $overwrite = null, $commitWithin = null, $buffer = 1500)
	{
		$this->initBufferAdd($overwrite, $commitWithin, $buffer);
		$this->addDocument($document);
	}
682832
public function setDocumentChangeSet(object $document, array $changeset) : void
    {
        $this->documentChangeSets[spl_object_hash($document)] = $changeset;
    }
90510
public function clear($documentName = null)
    {
        if ($documentName === null) {
            $this->identityMap =
            $this->documentIdentifiers =
            $this->originalDocumentData =
            $this->documentChangeSets =
            $this->documentStates =
            $this->scheduledForDirtyCheck =
            $this->documentInsertions =
            $this->documentUpserts =
            $this->documentUpdates =
            $this->documentDeletions =
            $this->extraUpdates =
            $this->collectionUpdates =
            $this->collectionDeletions =
            $this->parentAssociations =
            $this->orphanRemovals = array();

            if ($this->commitOrderCalculator !== null) {
                $this->commitOrderCalculator->clear();
            }
        } else {
            $visited = array();
            foreach ($this->identityMap as $className => $documents) {
                if ($className === $documentName) {
                    foreach ($documents as $document) {
                        $this->doDetach($document, $visited, true);
                    }
                }
            }
        }

        if ($this->evm->hasListeners(Events::onClear)) {
            $this->evm->dispatchEvent(Events::onClear, new Event\OnClearEventArgs($this->dm, $documentName));
        }
    }
1034221
public function computeChangeSets()
    {
        $this->computeScheduleInsertsChangeSets();
        $this->computeScheduleUpsertsChangeSets();

        // Compute changes for other MANAGED documents. Change tracking policies take effect here.
        foreach ($this->identityMap as $className => $documents) {
            $class = $this->dm->getClassMetadata($className);
            if ($class->isEmbeddedDocument) {
                /* we do not want to compute changes to embedded documents up front
                 * in case embedded document was replaced and its changeset
                 * would corrupt data. Embedded documents' change set will
                 * be calculated by reachability from owning document.
                 */
                continue;
            }

            // If change tracking is explicit or happens through notification, then only compute
            // changes on document of that type that are explicitly marked for synchronization.
            switch (true) {
                case ($class->isChangeTrackingDeferredImplicit()):
                    $documentsToProcess = $documents;
                    break;

                case (isset($this->scheduledForDirtyCheck[$className])):
                    $documentsToProcess = $this->scheduledForDirtyCheck[$className];
                    break;

                default:
                    $documentsToProcess = [];
            }

            foreach ($documentsToProcess as $document) {
                // Ignore uninitialized proxy objects
                if ($document instanceof Proxy && !$document->__isInitialized__) {
                    continue;
                }
                // Only MANAGED documents that are NOT SCHEDULED FOR INSERTION, UPSERT OR DELETION are processed here.
                $oid = spl_object_hash($document);
                if (isset($this->documentInsertions[$oid])
                    || isset($this->documentUpserts[$oid])
                    || isset($this->documentDeletions[$oid])
                    || !isset($this->documentStates[$oid])
                ) {
                    continue;
                }

                $this->computeChangeSet($class, $document);
            }
        }
    }
128468
function checksDo(listChecks, cb) {
    if (listChecks.length === 0) {
      return cb();
    }

    var check = listChecks.shift();
    check.func(check.key, function () {
      // schedule the next check
      setImmediate(checksDo, listChecks, cb);
    });
  }
430539
private function mapTimestamp(Document $document, \DateTime $created = null, \DateTime $changed = null)
    {
        $document->addField(
            $this->factory->createField('created', $created ? $created->format('c') : null, 'string')
        );

        $document->addField(
            $this->factory->createField('changed', $changed ? $changed->format('c') : null, 'string')
        );
    }
1130020
public function onBeforeWrite() {
		parent::onBeforeWrite();
		
		// dummy initial date
		if (!$this->OriginalPublishedDate) {
			// @TODO Fix this to be correctly localized!!
			$this->OriginalPublishedDate = date('Y-m-d 12:00:00');
		}
		
		$parent = $this->Parent();

		// just in case we've been moved, update our section
		$section = $this->findSection();
		$this->NewsSectionID = $section->ID;

		$newlyCreated = $section->ID == $parent->ID;
		$changedPublishDate = $this->isChanged('OriginalPublishedDate', 2);

		if (($changedPublishDate || $newlyCreated) && ($section->AutoFiling || $section->FilingMode)) {
			if (!$this->Created) {
				$this->Created = date('Y-m-d H:i:s');
			}
			$pp = $this->PartitionParent();
			if ($pp->ID != $this->ParentID) {
				$this->ParentID = $pp->ID;
			}
		}

	}
1342979
public function insert($document)
    {
        $class     = $this->dm->getClassMetadata(get_class($document));
        $changeset = $this->uow->getDocumentChangeSet($document);
        $qb        = $this->dm->createQueryBuilder($this->class->name);

        foreach ($class->propertyMetadata as $mapping) {
            $new = isset($changeset[$mapping->name][1]) ? $changeset[$mapping->name][1] : null;

            if (($new === null && !$mapping->nullable) || $mapping->isInverseSide) {
                continue;
            }

            if ($mapping->isMany()) {
                if ($mapping->strategy === PropertyMetadata::STORAGE_STRATEGY_ADD_TO_SET || $new->isEmpty()) {
                    continue;
                }

                $this->uow->unscheduleCollectionDeletion($new);
                $this->uow->unscheduleCollectionUpdate($new);
            }

            $qb->attr($mapping->name)->put($new);
        }

        //add a conditional preventing the resulting PutItem from overwriting
        //an existing record with the same primary key
        $class->createIdentifier($document)->addNotExistsToQueryCondition($qb->expr);

        $qb->getQuery()->execute();
    }
230226
private function commitPersisted()
    {
        $sortedDocuments = $this->sortObjects($this->scheduledForPersist);
        $client = $this->sm->getClient();

        foreach ($sortedDocuments as $entityName => $documents) {
            $classMetadata = $this->sm->getClassMetadata($entityName);
            $this->updatedIndexes[] = $classMetadata->index;
            $client->addDocuments($classMetadata, $documents);
        }
    }
51216
function bind(document, callback){
	var Node = getNodeConstructor(document);

	if(listeningDocs.indexOf(document) === -1) {
		if(!Node[_over]) {
			overrides.forEach(function(override){
				var res = override(Node, document);
				if(typeof res !== "undefined") {
					overrideTeardowns.push(res);
				}
			});
			overrideTeardowns.push(function(){
				Node[_over] = undefined;
			});
		}
		markAsInDocument(document.documentElement);
		listeningDocs.push(document);
	}

	Node[_over] = true;
	scheduler.register(document, callback);
}
533235
public function flush()
    {
        if (!empty($this->documents)) {
            $this->resource->addDocuments($this->storeId, $this->documents);
            $this->clearDocuments();
        }
    }
610475
private function updateNextCheckTime()
    {
        $hourToCheck = $this->getCheckTime();

        /** @var \OxidEsales\Eshop\Core\UtilsDate $utilsDate */
        $utilsDate = \OxidEsales\Eshop\Core\Registry::getUtilsDate();
        $nextCheckTime = $utilsDate->formTime('tomorrow', $hourToCheck);

        $this->getConfig()->saveSystemConfigParameter('str', 'sOnlineLicenseNextCheckTime', $nextCheckTime);
    }
311159
protected function isScheduled($objectHashId)
    {
        return isset($this->scheduledForInsertion[$objectHashId])
               || isset($this->scheduledForUpdate[$objectHashId])
               || isset($this->scheduledForDeletion[$objectHashId]);
    }