Пример #1
0
 public function getDraftVersions($objects)
 {
     $return = array();
     $user = eZUser::currentUser();
     foreach ($objects as $object) {
         // If this user already has a draft in this language
         $filters = array('contentobject_id' => $object->attribute('id'), 'status' => array(array(eZContentObjectVersion::STATUS_DRAFT, eZContentObjectVersion::STATUS_INTERNAL_DRAFT)), 'creator_id' => $user->attribute('contentobject_id'));
         $existingDrafts = eZContentObjectVersion::fetchFiltered($filters, 0, 1);
         if (!empty($existingDrafts)) {
             $return[] = $existingDrafts[0];
         } else {
             $return[] = $object->createNewVersion(false, true);
         }
     }
     return $return;
 }
Пример #2
0
    static function removeVersions( $versionStatus = false, $limit = false, $expiryTime = false, $fetchPortionSize = 50 )
    {
        $statuses = array( eZContentObjectVersion::STATUS_DRAFT,
                           eZContentObjectVersion::STATUS_PENDING,
                           eZContentObjectVersion::STATUS_REJECTED,
                           eZContentObjectVersion::STATUS_ARCHIVED,
                           eZContentObjectVersion::STATUS_INTERNAL_DRAFT );
        if ( $versionStatus === false )
        {
            $versionStatus = $statuses;
        }
        else if ( !is_array( $versionStatus ) )
        {
            $versionStatus = array( $versionStatus );
        }

        $versionStatus = array_unique( $versionStatus );
        $checkIntersect = array_intersect( $versionStatus, $statuses );
        if ( count( $checkIntersect ) != count( $versionStatus ) )
        {
            eZDebug::writeError( 'Invalid version status was passed in.', __METHOD__ );
            return false;
        }

        if ( $limit !== false and ( !is_numeric( $limit ) or $limit < 0 ) )
        {
            eZDebug::writeError( '$limit must be either false or positive numeric value.', __METHOD__ );
            return false;
        }

        if ( !is_numeric( $fetchPortionSize ) or $fetchPortionSize < 1 )
            $fetchPortionSize = 50;

        $filters = array();
        $filters['status'] = array( $versionStatus );
        if ( $expiryTime !== false )
            $filters['modified'] = array( '<', $expiryTime );

        $processedCount = 0;
        $db = eZDB::instance();
        while ( $processedCount < $limit or !$limit )
        {
            // fetch by versions by preset portion at a time to avoid memory overflow
            $tmpLimit = ( !$limit or ( $limit - $processedCount ) > $fetchPortionSize ) ?
                            $fetchPortionSize : $limit - $processedCount;
            $versions = eZContentObjectVersion::fetchFiltered( $filters, 0, $tmpLimit );
            if ( count( $versions ) < 1 )
                break;

            foreach ( $versions as $version )
            {
                $db->begin();
                $version->removeThis();
                $db->commit();
            }
            $processedCount += count( $versions );
        }
        return $processedCount;
    }
 /**
  * Returns current draft for current content object.
  * If there is no current draft, a new one will be created in provided language.
  * @param string|bool $lang Valid locale xxx-XX. If not provided, default edit language will be used
  * @see eZContentObject::createNewVersionIn()
  * @return eZContentObjectVersion
  */
 public function getCurrentDraft($lang = false)
 {
     $currentDraft = null;
     $db = eZDB::instance();
     // First check if we already have a draft
     $aFilter = array('contentobject_id' => $this->contentObject->attribute('id'), 'status' => array(array(eZContentObjectVersion::STATUS_DRAFT, eZContentObjectVersion::STATUS_INTERNAL_DRAFT)));
     $res = eZContentObjectVersion::fetchFiltered($aFilter, null, null);
     if (count($res) > 0 && $res[0] instanceof eZContentObjectVersion) {
         $currentDraft = $res[0];
         // FIXME : Fetch may result several drafts. We should take the last one (highest version)
         $currentDraft->setAttribute('modified', eZDateTime::currentTimeStamp());
         $currentDraft->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT);
         $currentDraft->store();
     } else {
         $db->begin();
         $currentDraft = $this->contentObject->createNewVersionIn($lang, false, $this->contentObject->attribute('current_version'));
         $currentDraft->store();
         $db->commit();
     }
     return $currentDraft;
 }