public static function status( $args ) { if ( count( $args ) != 2 ) { throw new ezcBaseFunctionalityNotSupportedException( 'status', 'Missing argument(s)' ); } list( $contentObjectId, $version ) = $args; $process = ezpContentPublishingProcess::fetchByContentObjectVersion( $contentObjectId, $version ); // No process: check if the object's still a draft // @todo Change to a PENDING check when applied (operation => step 2) if ( $process instanceof ezpContentPublishingProcess ) { $return = array(); $status = $process->attribute( 'status' ) == ezpContentPublishingProcess::STATUS_WORKING ? 'working' : 'finished'; switch( $process->attribute( 'status' ) ) { case ezpContentPublishingProcess::STATUS_WORKING: $status = 'working'; break; case ezpContentPublishingProcess::STATUS_FINISHED: $status = 'finished'; $objectVersion = $process->attribute( 'version' ); $object = $objectVersion->attribute( 'contentobject' ); $node = $object->attribute( 'main_node' ); $uri = $node->attribute( 'url_alias' ); eZURI::transformURI( $uri ); $return['node_uri'] = $uri; break; case ezpContentPublishingProcess::STATUS_PENDING: $status = 'pending'; break; case ezpContentPublishingProcess::STATUS_DEFERRED: $status = 'deferred'; $versionViewUri = "content/versionview/{$contentObjectId}/{$version}"; eZURI::transformURI( $versionViewUri ); $return['versionview_uri'] = $versionViewUri; break; } $return['status'] = $status; } else { $version = eZContentObjectVersion::fetchVersion( $version, $contentObjectId ); if ( $version === null ) throw new ezcBaseFunctionalityNotSupportedException( 'status', 'Object version not found' ); else $return = array( 'status' => 'queued' ); } return $return; }
/** * Returns the next processable item * @return ezpContentPublishingProcess The next object to process, or false if none is available */ public static function next() { $queuedProcess = eZPersistentObject::fetchObjectList( ezpContentPublishingProcess::definition(), null, array( 'status' => ezpContentPublishingProcess::STATUS_PENDING ), array( 'created' => 'desc' ), array( 'offset' => 0, 'length' => 1 ) ); if ( count( $queuedProcess ) == 0 ) return false; else return $queuedProcess[0]; }
/** * Checks WORKING processes, and removes from the queue those who are dead * * @return void */ private function cleanupDeadProcesses() { $processes = ezpContentPublishingProcess::fetchProcesses(ezpContentPublishingProcess::STATUS_WORKING); foreach ($processes as $process) { if (!$process->isAlive()) { $process->reset(); } } }
/** * Removes FINISHED processes rows from the db (in one db call) * method self-manages the removal, based on the defined cleanupInterval and cleanupAgeLimit * * @return void */ private function cleanupFinishedProcesses() { if ( time() < ( $this->cleanupLastTime + $this->cleanupInterval ) ) { return; } $processes = count( ezpContentPublishingProcess::fetchProcesses( ezpContentPublishingProcess::STATUS_FINISHED ) ); if ( $processes > 0 ) { //Remove all objects at once // this is required as the MySQL connection might be closed anytime by a fork try { eZDebug::writeNotice( "ASYNC:: removing processes entries marked as STATUS_FINISHED in database."); $db = eZDB::instance(); eZDB::setInstance( null ); $deleteBefore = time() - $this->cleanupAgeLimit; $definition = ezpContentPublishingProcess::definition(); $processTable = $definition['name']; $db->query( "DELETE from ". $processTable. " WHERE status =". ezpContentPublishingProcess::STATUS_FINISHED. " AND finished < ". $deleteBefore ); $this->cleanupLastTime = time(); } catch( eZDBException $e ) { // Do nothing, this will be retried until the DB is back up } } }
/** * Checks if an object exists in the queue, whatever the status is * @param int $objectId * @param int $version * @return bool */ public static function isQueued($objectId, $version) { $process = ezpContentPublishingProcess::fetchByContentObjectVersion($objectId, $version); return $process instanceof ezpContentPublishingProcess; }
/** * Make sure that eZPersistentObject can build instances of this class * @return array */ public static function definition() { $definition = parent::definition(); $definition['class_name'] = 'eZPerfLoggerContentPublishingProcess'; return $definition; }