| 1 |
# |
| 2 |
# This file is part of the LibreOffice project. |
| 3 |
# |
| 4 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 5 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 7 |
# |
| 8 |
# This file incorporates work covered by the following license notice: |
| 9 |
# |
| 10 |
# Licensed to the Apache Software Foundation (ASF) under one or more |
| 11 |
# contributor license agreements. See the NOTICE file distributed |
| 12 |
# with this work for additional information regarding copyright |
| 13 |
# ownership. The ASF licenses this file to you under the Apache |
| 14 |
# License, Version 2.0 (the "License"); you may not use this file |
| 15 |
# except in compliance with the License. You may obtain a copy of |
| 16 |
# the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 17 |
# |
| 18 |
|
| 19 |
package par2script::undefine; |
| 20 |
|
| 21 |
use par2script::globals; |
| 22 |
|
| 23 |
########################################################## |
| 24 |
# Removing in the script all the gids, that are listed |
| 25 |
# in undefine scp files |
| 26 |
########################################################## |
| 27 |
|
| 28 |
sub undefine_gids |
| 29 |
{ |
| 30 |
my ($parfilecontent) = @_; |
| 31 |
|
| 32 |
my $item; |
| 33 |
foreach $item ( @par2script::globals::allitems ) |
| 34 |
{ |
| 35 |
my $unitem = "Un$item"; |
| 36 |
|
| 37 |
for ( my $i = 0; $i <= $#{$parfilecontent}; $i++ ) |
| 38 |
{ |
| 39 |
if ( ${$parfilecontent}[$i] =~ /^\s*$unitem\s*(\w+?)\s*$/ ) |
| 40 |
{ |
| 41 |
my $gid = $1; |
| 42 |
delete($par2script::globals::definitions{$item}->{$gid}); |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
########################################################## |
| 49 |
# Collecting all subdirectories of a specified directory |
| 50 |
########################################################## |
| 51 |
|
| 52 |
sub collect_children_dirs |
| 53 |
{ |
| 54 |
my ($gid, $collector) = @_; |
| 55 |
|
| 56 |
my $diritem = "Directory"; |
| 57 |
my $parentkey = "ParentID"; |
| 58 |
|
| 59 |
if ( exists($par2script::globals::definitions{$diritem}) ) |
| 60 |
{ |
| 61 |
my $onedefinition; |
| 62 |
|
| 63 |
foreach $onedefinition (keys %{$par2script::globals::definitions{$diritem}}) |
| 64 |
{ |
| 65 |
if ( $par2script::globals::definitions{$diritem}->{$onedefinition}->{$parentkey} eq $gid ) |
| 66 |
{ |
| 67 |
push(@{$collector}, $onedefinition); |
| 68 |
collect_children_dirs($onedefinition, $collector); |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
########################################################## |
| 75 |
# Removing in the script complete profiles. |
| 76 |
# This includes the Profile and its ProfileItems. |
| 77 |
########################################################## |
| 78 |
|
| 79 |
sub remove_complete_item |
| 80 |
{ |
| 81 |
my ($item, $parfilecontent) = @_; |
| 82 |
|
| 83 |
my $removeitem = "Remove$item"; |
| 84 |
my $dependentkey = ""; |
| 85 |
my $collect_children = 0; |
| 86 |
my @gidcollector = (); |
| 87 |
my @dependentitems = (); |
| 88 |
|
| 89 |
if ( $item eq "Profile" ) |
| 90 |
{ |
| 91 |
@dependentitems = ("ProfileItem"); |
| 92 |
$dependentkey = "ProfileID"; |
| 93 |
} |
| 94 |
elsif ( $item eq "Directory" ) |
| 95 |
{ |
| 96 |
@dependentitems = ("File", "Shortcut", "Unixlink"); |
| 97 |
$dependentkey = "Dir"; |
| 98 |
$collect_children = 1; |
| 99 |
} |
| 100 |
|
| 101 |
for ( my $i = 0; $i <= $#{$parfilecontent}; $i++ ) |
| 102 |
{ |
| 103 |
if ( ${$parfilecontent}[$i] =~ /^\s*$removeitem\s*(\w+?)\s*$/ ) |
| 104 |
{ |
| 105 |
my $onegid = $1; |
| 106 |
push(@gidcollector, $onegid); |
| 107 |
if ( $collect_children ) { collect_children_dirs($onegid, \@gidcollector); } |
| 108 |
|
| 109 |
my $gid; |
| 110 |
foreach $gid (@gidcollector) |
| 111 |
{ |
| 112 |
delete($par2script::globals::definitions{$item}->{$gid}); |
| 113 |
|
| 114 |
# also deleting all dependent items, for example "ProfileItems" whose "ProfileID" is this "Profile" |
| 115 |
my $depitem; |
| 116 |
foreach $depitem ( @dependentitems ) |
| 117 |
{ |
| 118 |
if ( exists($par2script::globals::definitions{$depitem}) ) |
| 119 |
{ |
| 120 |
my $onedefinition; |
| 121 |
foreach $onedefinition (keys %{$par2script::globals::definitions{$depitem}}) |
| 122 |
{ |
| 123 |
if ( $par2script::globals::definitions{$depitem}->{$onedefinition}->{$dependentkey} eq $gid ) |
| 124 |
{ |
| 125 |
delete($par2script::globals::definitions{$depitem}->{$onedefinition}); |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
1; |