[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/content/ -> restore.php (source)

   1  <?php
   2  //
   3  // Created on: <03-May-2002 15:17:01 bf>
   4  //
   5  // SOFTWARE NAME: eZ publish
   6  // SOFTWARE RELEASE: 3.9.0
   7  // BUILD VERSION: 17785
   8  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
   9  // SOFTWARE LICENSE: GNU General Public License v2.0
  10  // NOTICE: >
  11  //   This program is free software; you can redistribute it and/or
  12  //   modify it under the terms of version 2.0  of the GNU General
  13  //   Public License as published by the Free Software Foundation.
  14  //
  15  //   This program is distributed in the hope that it will be useful,
  16  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18  //   GNU General Public License for more details.
  19  //
  20  //   You should have received a copy of version 2.0 of the GNU General
  21  //   Public License along with this program; if not, write to the Free
  22  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  23  //   MA 02110-1301, USA.
  24  //
  25  //
  26  
  27  
  28  include_once ( 'kernel/classes/ezcontentobject.php' );
  29  include_once ( 'kernel/classes/ezcontentclass.php' );
  30  include_once ( 'kernel/classes/ezcontentobjecttreenode.php' );
  31  
  32  include_once ( 'lib/ezutils/classes/ezhttptool.php' );
  33  
  34  include_once ( 'kernel/common/template.php' );
  35  
  36  $objectID = $Params['ObjectID'];
  37  $module =& $Params['Module'];
  38  
  39  $object =& eZContentObject::fetch( $objectID );
  40  if ( !is_object( $object ) )
  41  {
  42      return $Module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' );
  43  }
  44  if ( $object->attribute( 'status' ) != EZ_CONTENT_OBJECT_STATUS_ARCHIVED )
  45  {
  46      eZDebug::writeError( "Object with ID " . (int)$objectID . " is not archived, cannot restore." );
  47      return $module->redirectToView( 'trash' );
  48  }
  49  
  50  $ini =& eZINI::instance();
  51  $userClassID = $ini->variable( "UserSettings", "UserClassID" );
  52  
  53  if ( $module->isCurrentAction( 'Cancel' ) )
  54  {
  55      return $module->redirectToView( 'trash' );
  56  }
  57  
  58  $class =& $object->contentClass();
  59  $version = $object->attribute( 'current' );
  60  
  61  $location = null;
  62  $assignments = $version->attribute( 'node_assignments' );
  63  foreach ( $assignments as $assignment )
  64  {
  65      $opCode = $assignment->attribute( 'op_code' );
  66      $opCode &= ~1;
  67      // We only include assignments which create or nops.
  68      if ( $opCode == EZ_NODE_ASSIGNMENT_OP_CODE_CREATE_NOP ||
  69           $opCode == EZ_NODE_ASSIGNMENT_OP_CODE_NOP )
  70      {
  71          $node = $assignment->attribute( 'parent_node_obj' );
  72          if ( !$node )
  73          {
  74              continue;
  75          }
  76          if ( $assignment->attribute( 'is_main' ) )
  77          {
  78              $parentNode = $assignment->attribute( 'parent_node_obj' );
  79              $parentNodeObject = $parentNode->attribute( 'object' );
  80              $canCreate = $parentNode->checkAccess( 'create', $class->attribute( 'id' ), $parentNodeObject->attribute( 'contentclass_id' ) ) == 1;
  81              if ( !$canCreate )
  82              {
  83                  continue;
  84              }
  85              $location = $assignment;
  86              break;
  87          }
  88          else if ( !$location )
  89          {
  90              $parentNode = $assignment->attribute( 'parent_node_obj' );
  91              $parentNodeObject = $parentNode->attribute( 'object' );
  92              $canCreate = $parentNode->checkAccess( 'create', $class->attribute( 'id' ), $parentNodeObject->attribute( 'contentclass_id' ) ) == 1;
  93              if ( !$canCreate )
  94              {
  95                  continue;
  96              }
  97              $location = $assignment;
  98          }
  99      }
 100  }
 101  
 102  if ( $module->isCurrentAction( 'Confirm' ) )
 103  {
 104      $type = $module->actionParameter( 'RestoreType' );
 105      if ( $type == 1 )
 106      {
 107          $selectedNodeIDArray = array( $location->attribute( 'parent_node' ) );
 108          $module->setCurrentAction( 'AddLocation' );
 109      }
 110      elseif ( $type == 2 )
 111      {
 112          include_once ( 'kernel/classes/ezcontentbrowse.php' );
 113          $languageCode = $object->attribute( 'initial_language_code' );
 114          eZContentBrowse::browse( array( 'action_name' => 'AddNodeAssignment',
 115                                          'description_template' => 'design:content/browse_placement.tpl',
 116                                          'keys' => array( 'class' => $class->attribute( 'id' ),
 117                                                           'class_id' => $class->attribute( 'identifier' ),
 118                                                           'classgroup' => $class->attribute( 'ingroup_id_list' ),
 119                                                           'section' => $object->attribute( 'section_id' ) ),
 120                                          'ignore_nodes_select' => array(),
 121                                          'ignore_nodes_click'  => array(),
 122                                          'persistent_data' => array( 'ContentObjectID' => $objectID,
 123                                                                      'AddLocationAction' => '1' ),
 124                                          'content' => array( 'object_id' => $objectID,
 125                                                              'object_version' => $version->attribute( 'version' ),
 126                                                              'object_language' => $languageCode ),
 127                                          'cancel_page' => '/content/trash/',
 128                                          'from_page' => "/content/restore/" . $objectID ),
 129                                   $module );
 130  
 131          return;
 132      }
 133  }
 134  
 135  if ( $module->isCurrentAction( 'AddLocation' ) )
 136  {
 137      // If $selectedNodeIDArray is already set then use it as it is,
 138      // if not get the browse data.
 139      if ( !isset( $selectedNodeIDArray ) )
 140      {
 141          include_once ( 'kernel/classes/ezcontentbrowse.php' );
 142          $selectedNodeIDArray = eZContentBrowse::result( 'AddNodeAssignment' );
 143          if ( !$selectedNodeIDArray )
 144          {
 145              return $module->redirectToView( 'trash' );
 146          }
 147      }
 148  
 149      $db =& eZDB::instance();
 150      $db->begin();
 151      $locationAdded = false;
 152      $mainNodeID = false;
 153  
 154      $newLocationList    = array();
 155      $failedLocationList = array();
 156      foreach ( $selectedNodeIDArray as $selectedNodeID )
 157      {
 158          $parentNode = eZContentObjectTreeNode::fetch( $selectedNodeID );
 159          $parentNodeObject =& $parentNode->attribute( 'object' );
 160  
 161          $canCreate = $parentNode->checkAccess( 'create', $class->attribute( 'id' ), $parentNodeObject->attribute( 'contentclass_id' ) ) == 1;
 162  
 163          if ( $canCreate )
 164          {
 165              if ( $mainNodeID === false )
 166              {
 167                  $isMain = true;
 168              }
 169              $newLocationList[] = array( 'parent_node_id' => $selectedNodeID,
 170                                          'is_main'        => $isMain );
 171  
 172              $locationAdded = true;
 173          }
 174          else
 175          {
 176              $failedLocationList[] = array( 'parent_node_id' => $selectedNodeID );
 177          }
 178      }
 179  
 180      // Check if we have failures
 181      if ( count( $failedLocationList ) > 0 )
 182      {
 183          return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
 184      }
 185  
 186      // Remove all existing assignments, only our new ones should be present.
 187      foreach ( $version->attribute( 'node_assignments' ) as $assignment )
 188      {
 189          $assignment->purge();
 190      }
 191  
 192      // Add all new locations
 193      foreach ( $newLocationList as $newLocation )
 194      {
 195          $version->assignToNode( $newLocation['parent_node_id'], $newLocation['is_main'] );
 196      }
 197  
 198      $object->setAttribute( 'status', EZ_CONTENT_OBJECT_STATUS_DRAFT );
 199      $object->store();
 200      $version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
 201      $version->store();
 202  
 203      $user =& eZUser::currentUser();
 204      include_once ( 'lib/ezutils/classes/ezoperationhandler.php' );
 205      $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $objectID,
 206                                                                                   'version' => $version->attribute( 'version' ) ) );
 207      if ( ( array_key_exists( 'status', $operationResult ) && $operationResult['status'] != EZ_MODULE_OPERATION_CONTINUE ) )
 208      {
 209          switch( $operationResult['status'] )
 210          {
 211              case EZ_MODULE_OPERATION_HALTED:
 212              case EZ_MODULE_OPERATION_CANCELED:
 213              {
 214                  $module->redirectToView( 'trash' );
 215              }
 216          }
 217      }
 218      $objectID = $object->attribute( 'id' );
 219      $object = eZContentObject::fetch( $objectID );
 220      $mainNodeID = $object->attribute( 'main_node_id' );
 221  
 222      include_once ( 'kernel/classes/ezcontentobjecttrashnode.php' );
 223      eZContentObjectTrashNode::purgeForObject( $objectID  );
 224  
 225      if ( $locationAdded )
 226      {
 227          if ( $object->attribute( 'contentclass_id' ) == $userClassID )
 228          {
 229              eZUser::cleanupCache();
 230          }
 231      }
 232      $db->commit();
 233      $module->redirectToView( 'view', array( 'full', $mainNodeID ) );
 234      return;
 235  }
 236  
 237  $tpl =& templateInit();
 238  
 239  $res =& eZTemplateDesignResource::instance();
 240  
 241  $designKeys = array( array( 'object', $object->attribute( 'id' ) ), // Object ID
 242                       array( 'class', $class->attribute( 'id' ) ), // Class ID
 243                       array( 'class_identifier', $class->attribute( 'identifier' ) ) ); // Class identifier
 244  
 245  $res->setKeys( $designKeys );
 246  
 247  $Result = array();
 248  
 249  $tpl->setVariable( "object",   $object );
 250  $tpl->setVariable( "version",  $version );
 251  $tpl->setVariable( "location", $location );
 252  
 253  $Result['content'] = $tpl->fetch( 'design:content/restore.tpl' );
 254  $Result['path'] = array( array( 'uri'  => false,
 255                                  'text' => ezi18n( "kernel/content/restore", "Restore object" ) ),
 256                           array( 'uri'  => false,
 257                                  'text' => $object->attribute( 'name' ) ) );
 258  
 259  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7