1#************************************************************************* 2# 3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4# 5# Copyright 2000, 2010 Oracle and/or its affiliates. 6# 7# OpenOffice.org - a multi-platform office productivity suite 8# 9# This file is part of OpenOffice.org. 10# 11# OpenOffice.org is free software: you can redistribute it and/or modify 12# it under the terms of the GNU Lesser General Public License version 3 13# only, as published by the Free Software Foundation. 14# 15# OpenOffice.org 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 Lesser General Public License version 3 for more details 19# (a copy is included in the LICENSE file that accompanied this code). 20# 21# You should have received a copy of the GNU Lesser General Public License 22# version 3 along with OpenOffice.org. If not, see 23# <http://www.openoffice.org/license.html> 24# for a copy of the LGPLv3 License. 25# 26#************************************************************************* 27 28package par2script::undefine; 29 30use par2script::globals; 31 32########################################################## 33# Removing in the script all the gids, that are listed 34# in undefine scp files 35########################################################## 36 37sub undefine_gids 38{ 39 my ($parfilecontent) = @_; 40 41 my $item; 42 foreach $item ( @par2script::globals::allitems ) 43 { 44 my $unitem = "Un$item"; 45 46 for ( my $i = 0; $i <= $#{$parfilecontent}; $i++ ) 47 { 48 if ( ${$parfilecontent}[$i] =~ /^\s*$unitem\s*(\w+?)\s*$/ ) 49 { 50 my $gid = $1; 51 delete($par2script::globals::definitions{$item}->{$gid}); 52 } 53 } 54 } 55} 56 57########################################################## 58# Collecting all subdirectories of a specified directory 59########################################################## 60 61sub collect_children_dirs 62{ 63 my ($gid, $collector) = @_; 64 65 my $diritem = "Directory"; 66 my $parentkey = "ParentID"; 67 68 if ( exists($par2script::globals::definitions{$diritem}) ) 69 { 70 my $onedefinition; 71 72 foreach $onedefinition (keys %{$par2script::globals::definitions{$diritem}}) 73 { 74 if ( $par2script::globals::definitions{$diritem}->{$onedefinition}->{$parentkey} eq $gid ) 75 { 76 push(@{$collector}, $onedefinition); 77 collect_children_dirs($onedefinition, $collector); 78 } 79 } 80 } 81} 82 83########################################################## 84# Removing in the script complete profiles. 85# This includes the Profile and its ProfileItems. 86########################################################## 87 88sub remove_complete_item 89{ 90 my ($item, $parfilecontent) = @_; 91 92 my $removeitem = "Remove$item"; 93 my $dependentkey = ""; 94 my $collect_children = 0; 95 my @gidcollector = (); 96 my @dependentitems = (); 97 98 if ( $item eq "Profile" ) 99 { 100 @dependentitems = ("ProfileItem"); 101 $dependentkey = "ProfileID"; 102 } 103 elsif ( $item eq "Directory" ) 104 { 105 @dependentitems = ("File", "Shortcut", "Unixlink"); 106 $dependentkey = "Dir"; 107 $collect_children = 1; 108 } 109 110 for ( my $i = 0; $i <= $#{$parfilecontent}; $i++ ) 111 { 112 if ( ${$parfilecontent}[$i] =~ /^\s*$removeitem\s*(\w+?)\s*$/ ) 113 { 114 my $onegid = $1; 115 push(@gidcollector, $onegid); 116 if ( $collect_children ) { collect_children_dirs($onegid, \@gidcollector); } 117 118 my $gid; 119 foreach $gid (@gidcollector) 120 { 121 delete($par2script::globals::definitions{$item}->{$gid}); 122 123 # also deleting all dependent items, for example "ProfileItems" whose "ProfileID" is this "Profile" 124 my $depitem; 125 foreach $depitem ( @dependentitems ) 126 { 127 if ( exists($par2script::globals::definitions{$depitem}) ) 128 { 129 my $onedefinition; 130 foreach $onedefinition (keys %{$par2script::globals::definitions{$depitem}}) 131 { 132 if ( $par2script::globals::definitions{$depitem}->{$onedefinition}->{$dependentkey} eq $gid ) 133 { 134 delete($par2script::globals::definitions{$depitem}->{$onedefinition}); 135 } 136 } 137 } 138 } 139 } 140 } 141 } 142} 143 1441; 145