Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezpcontentpublishingprocess.php
Go to the documentation of this file.
1 <?php
18 class ezpContentPublishingProcess extends eZPersistentObject
19 {
20 const STATUS_WORKING = 1;
21 const STATUS_FINISHED = 2;
22 const STATUS_PENDING = 3;
23
27 const STATUS_DEFERRED = 4;
28
32 const STATUS_UNKNOWN = 5;
33
38 public static function definition()
39 {
40 static $definition = array(
41 'fields' => array( 'ezcontentobject_version_id' => array( 'name' => 'ContentObjectVersionID',
42 'datatype' => 'integer',
43 'default' => 0,
44 'required' => true,
45 'foreign_class' => 'eZContentObjectVersion',
46 'foreign_attribute' => 'id',
47 'multiplicity' => '1..*' ),
48 'pid' => array( 'name' => 'PID',
49 'datatype' => 'integer',
50 'default' => 0,
51 'required' => false ),
52 'status' => array( 'name' => 'Status',
53 'datatype' => 'integer',
54 'default' => 0,
55 'required' => true ),
56 'started' => array( 'name' => 'Started',
57 'datatype' => 'integer',
58 'default' => 0,
59 'required' => true ),
60 'created' => array( 'name' => 'Created',
61 'datatype' => 'integer',
62 'default' => 0,
63 'required' => true ),
64 'finished' => array( 'name' => 'Finished',
65 'datatype' => 'integer',
66 'default' => 0,
67 'required' => true ) ),
68 'keys' => array( 'ezcontentobject_version_id' ),
69 'function_attributes' => array( 'version' => 'version' ),
70 'class_name' => 'ezpContentPublishingProcess',
71 'increment_key' => null,
72 'sort' => array( 'created' => 'asc' ),
73 'name' => 'ezpublishingqueueprocesses' );
74 return $definition;
75 }
76
81 public function version()
82 {
83 if ( $this->versionObject === null )
84 $this->versionObject = eZContentObjectVersion::fetch( $this->attribute( 'ezcontentobject_version_id' ) );
85
86 return $this->versionObject;
87 }
88
94 public static function fetchByContentVersionId( $contentObjectVersionId )
95 {
96 return parent::fetchObject(
97 self::definition(),
98 false,
99 array( 'ezcontentobject_version_id' => $contentObjectVersionId )
100 );
101 }
102
109 public static function fetchByContentObjectVersion( $contentObjectId, $version )
110 {
111 $contentObjectVersion = eZContentObjectVersion::fetchVersion( $version, $contentObjectId );
112 if ( $contentObjectVersion instanceof eZContentObjectVersion )
113 {
114 $return = self::fetchByContentVersionId( $contentObjectVersion->attribute( 'id' ) );
115 return $return;
116 }
117 else
118 {
119 return false;
120 }
121 }
122
127 public static function currentWorkingProcessCount()
128 {
129 return self::count( self::definition(), array( 'status' => self::STATUS_WORKING ) );
130 }
131
137 public static function isProcessing( eZContentObjectVersion $versionObject )
138 {
139 $count = parent::count(
140 self::definition(),
141 array(
142 'ezcontentobject_version_id' => $versionObject->attribute( 'id' ),
143 // 'status' => self::STATUS_WORKING // not used yet
144 )
145 );
146 return ( $count != 0 );
147 }
148
156 public function publish()
157 {
158 $contentObjectId = $this->version()->attribute( 'contentobject_id' );
159 $contentObjectVersion = $this->version()->attribute( 'version' );
160
161 // $processObject = ezpContentPublishingProcess::fetchByContentObjectVersion( $contentObjectId, $contentObjectVersion );
162 $this->setStatus( self::STATUS_WORKING, true, "beginning publishing" );
163
164 // prepare the cluster file handler for the fork
165 eZClusterFileHandler::preFork();
166
167 $pid = pcntl_fork();
168
169 // force the DB connection closed
170 $db = eZDB::instance();
171 $db->close();
172 $db = null;
173 eZDB::setInstance( null );
174
175 // Force the new stack DB connection closed as well
176 try
177 {
178 $kernel = ezpKernel::instance();
179 if ( $kernel->hasServiceContainer() )
180 {
181 $serviceContainer = $kernel->getServiceContainer();
182 $dbHandler = $serviceContainer->get( 'ezpublish.connection' );
183 $factory = $serviceContainer->get( 'ezpublish.api.storage_engine.legacy.dbhandler.factory' );
184 $dbHandler->setDbHandler(
185 $factory->buildLegacyDbHandler()->getDbHandler()
186 );
187 }
188 }
189 catch ( LogicException $e )
190 {
191 // we just ignore this, since it means that we are running in a pure legacy context
192 }
193
194 // Force the cluster DB connection closed if the cluster handler is DB based
195 $cluster = eZClusterFileHandler::instance();
196
197 // error, cancel
198 if ( $pid == -1 )
199 {
200 $this->setStatus( self::STATUS_PENDING, true, "pcntl_fork() failed" );
201 return false;
202 }
203 else if ( $pid )
204 {
205 return $pid;
206 }
207
208 // child process
209 try
210 {
211 $myPid = getmypid();
212 pcntl_signal( SIGCHLD, SIG_IGN );
213
214 $this->setAttribute( 'pid', $myPid );
215 $this->setAttribute( 'started', time() );
216 $this->store( array( 'pid', 'started' ) );
217
218 // login the version's creator to make sure publishing happens as if ran synchronously
219 $creatorId = $this->version()->attribute( 'creator_id' );
220 $creator = eZUser::fetch( $creatorId );
221 eZUser::setCurrentlyLoggedInUser( $creator, $creatorId );
222 unset( $creator, $creatorId );
223
224 $operationResult = eZOperationHandler::execute( 'content', 'publish',
225 array( 'object_id' => $contentObjectId, 'version' => $contentObjectVersion )
226 );
227
228 // Statuses other than CONTINUE require special handling
229 if ( $operationResult['status'] != eZModuleOperationInfo::STATUS_CONTINUE )
230 {
231 if ( $operationResult['status'] == eZModuleOperationInfo::STATUS_HALTED )
232 {
233 // deferred to crontab
234 if ( strpos( $operationResult['result']['content'], 'Deffered to cron' ) !== false )
235 $processStatus = self::STATUS_DEFERRED;
236 else
237 $processStatus = self::STATUS_UNKNOWN;
238 }
239 else
240 {
241 $processStatus = self::STATUS_UNKNOWN;
242 }
243 }
244 else
245 {
246 $processStatus = self::STATUS_FINISHED;
247 }
248
249 // mark the process as completed
250 $this->setAttribute( 'pid', 0 );
251 $this->setStatus( $processStatus, false, "publishing operation finished" );
252 $this->setAttribute( 'finished', time() );
253 $this->store( array( 'status', 'finished', 'pid' ) );
254
255 // Call the postProcessing hook
256 ezpContentPublishingQueue::signals()->emit( 'postHandling', $contentObjectId, $contentObjectVersion, $processStatus );
257 }
258 catch( eZDBException $e )
259 {
260 $this->reset( "database error: " . $e->getMessage() );
261 }
262
263 // generate static cache
264 $ini = eZINI::instance();
265 if ( $ini->variable( 'ContentSettings', 'StaticCache' ) == 'enabled' )
266 {
267 $staticCacheHandlerClassName = $ini->variable( 'ContentSettings', 'StaticCacheHandler' );
268 $staticCacheHandlerClassName::executeActions();
269 }
270
271 eZScript::instance()->shutdown();
272 exit;
273 }
274
280 public static function queue( eZContentObjectVersion $version )
281 {
282 $row = array(
283 'ezcontentobject_version_id' => $version->attribute( 'id' ),
284 'created' => time(),
285 'status' => self::STATUS_PENDING,
286 );
287 $processObject = new self( $row );
288 $processObject->store();
289
290 return $processObject;
291 }
292
298 public static function fetchProcesses( $status )
299 {
300 if ( !in_array( $status, array( self::STATUS_FINISHED, self::STATUS_PENDING, self::STATUS_WORKING ) ) )
301 throw new ezcBaseValueException( '$status', $status, array( self::STATUS_FINISHED, self::STATUS_PENDING, self::STATUS_WORKING ), 'parameter' );
302
303 return parent::fetchObjectList( self::definition(), false,
304 array( 'status' => $status ),
305 array( 'created' => 'asc' ) );
306 }
307
314 public function isAlive()
315 {
316 if ( $this->attribute( 'status' ) != self::STATUS_WORKING )
317 throw new Exception( 'The process\'s status isn\'t \'working\'' );
318
319 // sending 0 only checks if the process is alive (and if the current process is allowed to send signals to it)
320 $return = ( posix_kill( $this->attribute( 'pid' ), 0 ) === true );
321 return $return;
322 }
323
331 public function reset( $message )
332 {
333 $this->setStatus( self::STATUS_PENDING, false, "::reset() with message '$message'" );
334 $this->setAttribute( 'pid', 0 );
335 $this->store( array( 'status', 'pid' ) );
336 }
337
343 private function setStatus( $status, $store = true, $reason = null )
344 {
345 $this->logStatusChange( $status, $reason );
346 $this->setAttribute( 'status', $status );
347 if ( $store )
348 {
349 $this->store( array( 'status' ) );
350 }
351 }
352
359 private function logStatusChange( $status, $reason = null )
360 {
361 $contentObjectId = $this->version()->attribute( 'contentobject_id' );
362 $versionNumber = $this->version()->attribute( 'version' );
363 eZDebugSetting::writeDebug(
364 'kernel-content-publish',
365 sprintf(
366 "process #%d, content %d.%d, status changed to %s (reason: %s)",
367 $this->attribute( 'ezcontentobject_version_id' ),
368 $contentObjectId,
369 $versionNumber,
370 $this->getStatusString( $status ),
371 $reason ?: "none given"
372 ),
373 'Asynchronous publishing process status changed'
374 );
375 }
376
377 private function getStatusString( $status )
378 {
379 $statusMap = array(
380 self::STATUS_PENDING => 'pending',
381 self::STATUS_DEFERRED => 'deferred',
382 self::STATUS_FINISHED => 'finished',
383 self::STATUS_UNKNOWN => 'unknown',
384 self::STATUS_WORKING => 'working'
385 );
386
387 return isset( $statusMap[$status] ) ? $statusMap[$status] : "<<invalid status>>";
388 }
389
390 private $versionObject = null;
391 }
$message
$message
Definition: admin/message.php:51
$status
$status
Definition: bugedit.php:473
eZClusterFileHandler\instance
static instance( $filename=false)
Definition: ezclusterfilehandler.php:22
eZClusterFileHandler\preFork
static preFork()
Definition: ezclusterfilehandler.php:152
eZDBException
Definition: exception.php:20
eZDebugSetting\writeDebug
static writeDebug( $conditionName, $string, $label="")
Definition: ezdebugsetting.php:128
eZPersistentObject
Definition: ezpersistentobject.php:34
eZPersistentObject\store
store( $fieldFilters=null)
Definition: ezpersistentobject.php:305
eZPersistentObject\setAttribute
setAttribute( $attr, $val)
Definition: ezpersistentobject.php:1375
eZPersistentObject\count
static count( $def, $conds=null, $field=null)
Definition: ezpersistentobject.php:188
eZPersistentObject\attribute
attribute( $attr, $noFunction=false)
Definition: ezpersistentobject.php:1330
$ini
$ini
Definition: classes/admin/linklist.php:64
ezpContentPublishingProcess
Definition: ezpcontentpublishingprocess.php:19
ezpContentPublishingProcess\publish
publish()
Definition: ezpcontentpublishingprocess.php:156
ezpContentPublishingProcess\STATUS_PENDING
const STATUS_PENDING
Definition: ezpcontentpublishingprocess.php:22
ezpContentPublishingProcess\STATUS_WORKING
const STATUS_WORKING
Definition: ezpcontentpublishingprocess.php:20
ezpContentPublishingProcess\STATUS_FINISHED
const STATUS_FINISHED
Definition: ezpcontentpublishingprocess.php:21
ezpContentPublishingProcess\fetchByContentVersionId
static fetchByContentVersionId( $contentObjectVersionId)
Definition: ezpcontentpublishingprocess.php:94
ezpContentPublishingProcess\setStatus
setStatus( $status, $store=true, $reason=null)
Definition: ezpcontentpublishingprocess.php:343
ezpContentPublishingProcess\reset
reset( $message)
Definition: ezpcontentpublishingprocess.php:331
ezpContentPublishingProcess\$versionObject
$versionObject
Definition: ezpcontentpublishingprocess.php:390
ezpContentPublishingProcess\STATUS_UNKNOWN
const STATUS_UNKNOWN
Definition: ezpcontentpublishingprocess.php:32
ezpContentPublishingProcess\queue
static queue(eZContentObjectVersion $version)
Definition: ezpcontentpublishingprocess.php:280
ezpContentPublishingProcess\getStatusString
getStatusString( $status)
Definition: ezpcontentpublishingprocess.php:377
ezpContentPublishingProcess\fetchProcesses
static fetchProcesses( $status)
Definition: ezpcontentpublishingprocess.php:298
ezpContentPublishingProcess\logStatusChange
logStatusChange( $status, $reason=null)
Definition: ezpcontentpublishingprocess.php:359
ezpContentPublishingProcess\fetchByContentObjectVersion
static fetchByContentObjectVersion( $contentObjectId, $version)
Definition: ezpcontentpublishingprocess.php:109
ezpContentPublishingProcess\isProcessing
static isProcessing(eZContentObjectVersion $versionObject)
Definition: ezpcontentpublishingprocess.php:137
ezpContentPublishingProcess\definition
static definition()
Definition: ezpcontentpublishingprocess.php:38
ezpContentPublishingProcess\version
version()
Definition: ezpcontentpublishingprocess.php:81
ezpContentPublishingProcess\STATUS_DEFERRED
const STATUS_DEFERRED
Definition: ezpcontentpublishingprocess.php:27
ezpContentPublishingProcess\isAlive
isAlive()
Definition: ezpcontentpublishingprocess.php:314
ezpContentPublishingProcess\currentWorkingProcessCount
static currentWorkingProcessCount()
Definition: ezpcontentpublishingprocess.php:127
ezpContentPublishingQueue\signals
static signals()
Definition: ezpcontentpublishingqueue.php:26
ezpKernel\instance
static instance()
Definition: ezpkernel.php:139
$version
$version
Definition: ezabout/user/datasupplier.php:29
$db
$db
Definition: ezarticle/user/authorlist.php:53
$row
$row
Definition: ezcalendar/user/dayview.php:403
exit
exit
Definition: folder.php:81
$count
$count
Definition: onlinetypelist.php:108
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.