|
eZ Publish
[4.0]
|
00001 #!/usr/bin/env php 00002 <?php 00003 // 00004 // Created on: <22-Aug-2006 12:05:27 ks> 00005 // 00006 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00007 // SOFTWARE NAME: eZ Publish 00008 // SOFTWARE RELEASE: 4.0.x 00009 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00010 // SOFTWARE LICENSE: GNU General Public License v2.0 00011 // NOTICE: > 00012 // This program is free software; you can redistribute it and/or 00013 // modify it under the terms of version 2.0 of the GNU General 00014 // Public License as published by the Free Software Foundation. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of version 2.0 of the GNU General 00022 // Public License along with this program; if not, write to the Free 00023 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00024 // MA 02110-1301, USA. 00025 // 00026 // 00027 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00028 // 00029 00030 //include_once( 'lib/ezutils/classes/ezcli.php' ); 00031 //include_once( 'kernel/classes/ezscript.php' ); 00032 00033 require 'autoload.php'; 00034 00035 $cli = eZCLI::instance(); 00036 00037 $script = eZScript::instance( array( 'description' => "\nThis script is optional for upgrading to 3.10.\n" . 00038 "The script adds a role which contains a policy 'content/tipafriend' and" . 00039 "\nassigns this role to all user groups except anonymous. That will give " . 00040 "\npossibility to use tipafriend view for all users except anonymous." . 00041 "\n\nNote: siteacces, login and password options are required and" . 00042 "\nmust to be set to admin siteaccess and admin login/passsword accordingly" . 00043 "\n\n(See doc/feature/(3.8|3.9|3.10)/content_tipafriend_policy.txt for more information).", 00044 'use-session' => false, 00045 'use-modules' => false, 00046 'use-extensions' => true ) ); 00047 00048 $script->startup(); 00049 $options = $script->getOptions( '', '', false, false, 00050 array( 'siteaccess' => true, 00051 'user' => true ) ); 00052 00053 $siteAccess = $options['siteaccess'] ? $options['siteaccess'] : false; 00054 $script->setUseSiteAccess( $siteAccess ); 00055 $script->initialize(); 00056 00057 $cli->notice( "\nStart." ); 00058 00059 $contentIni = eZINI::instance( 'content.ini' ); 00060 $userRootNodeID = $contentIni->variable( 'NodeSettings', 'UserRootNode' ); 00061 00062 $siteIni = eZINI::instance( 'site.ini' ); 00063 $anonymousUserID = $siteIni->variable( 'UserSettings', 'AnonymousUserID' ); 00064 $anonymousUser = eZUser::fetch( $anonymousUserID ); 00065 $anonymousUsers = array(); 00066 if ( is_object( $anonymousUser ) ) 00067 { 00068 $anonymousUsers = $anonymousUser->groups(); 00069 $anonymousUsers[] = $anonymousUserID; 00070 } 00071 00072 //include_once( 'kernel/classes/ezcontentobjecttreenode.php' ); 00073 //include_once( 'kernel/classes/ezrole.php' ); 00074 00075 $topUserNodes = eZContentObjectTreeNode::subTreeByNodeID( array( 'Depth' => 1 ), $userRootNodeID ); 00076 00077 if ( count( $topUserNodes ) == 0 ) 00078 { 00079 $cli->warning( "Unable to retrieve the user root node. Please make sure\n" . 00080 "you log in to the system with the administrator's user\n" . 00081 "acount by using the -l and -p command line options." ); 00082 $script->shutdown( 1 ); 00083 } 00084 00085 $roleName = 'Tipafriend Role'; 00086 $role = eZRole::fetchByName( $roleName ); 00087 if ( is_object( $role ) ) 00088 { 00089 $cli->warning( "The 'Tipafriend Role' already exists in the system. This means that\n" . 00090 "the script was already run before or the same role was added manually.\n" . 00091 "The role will not be added. Check the role settings of the system." ); 00092 } 00093 else 00094 { 00095 $userInput = ''; 00096 $usersToAssign = array(); 00097 $stdin = fopen( "php://stdin", "r+" ); 00098 foreach ( $topUserNodes as $userNode ) 00099 { 00100 if ( $userInput != 'a' ) 00101 { 00102 $name = $userNode->getName(); 00103 if ( in_array( $userNode->attribute( 'contentobject_id' ), $anonymousUsers ) ) 00104 $cli->output( "Note: the '$name' group/user is anonymous." ); 00105 $cli->output( "Assign 'Tipafriend Role' to the '$name' group/user? y(yes)/n(no)/a(all)/s(skip all): ", false ); 00106 $userInput = fgets( $stdin ); 00107 $userInput = trim( $userInput ); 00108 } 00109 if ( $userInput == 'y' or $userInput == 'a' ) 00110 { 00111 $usersToAssign[] = $userNode->attribute( 'contentobject_id' ); 00112 } 00113 else if ( $userInput == 's' ) 00114 { 00115 break; 00116 } 00117 } 00118 fclose( $stdin ); 00119 00120 if ( count( $usersToAssign ) > 0 ) 00121 { 00122 $role = eZRole::create( $roleName ); 00123 $role->store(); 00124 $role->appendPolicy( 'content', 'tipafriend' ); 00125 $role->store(); 00126 00127 foreach ( $usersToAssign as $userID ) 00128 { 00129 $role->assignToUser( $userID ); 00130 } 00131 // clear role cache 00132 eZRole::expireCache(); 00133 //include_once( 'kernel/classes/ezcontentcachemanager.php' ); 00134 eZContentCacheManager::clearAllContentCache(); 00135 // clear policy cache 00136 eZUser::cleanupCache(); 00137 } 00138 else 00139 { 00140 $cli->notice( "\nThe role wasn't added because you didn't choose any group to assign." ); 00141 } 00142 } 00143 00144 $cli->notice( "\nDone." ); 00145 $script->shutdown(); 00146 00147 ?>