Changeset 12543


Ignore:
Timestamp:
09/18/11 11:45:57 (20 months ago)
Author:
PaulHarvey
Message:

Item11135: wiring up the new store API - now the unit test infrastructure doesn't crash - next up, make some tests pass

Location:
branches/scratch/core/lib
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/scratch/core/lib/Foswiki.pm

    r12540 r12543  
    18921892    #Monitor::MARK("Loaded default prefs"); 
    18931893 
     1894        #pre-cache the admin user membership before we foswiki-setuid to session user 
     1895    $this->{users}->eachGroupMember($Foswiki::cfg{SuperAdminGroup}); 
     1896 
    18941897    # SMELL: what happens if we move this into the Foswiki::Users::new? 
    18951898    $this->{user} = $this->{users}->initialiseUser( $this->{remoteUser} ); 
    1896     $this->store->changeDefaultUser($this->{user}); 
     1899    $this->{store}->changeDefaultUser($this->{user}); 
    18971900 
    18981901    #Monitor::MARK("Initialised user"); 
     
    36923695 
    36933696    ASSERT( UNTAINTED($web), 'web is tainted' ) if DEBUG; 
    3694     return $this->{store}->webExists($web); 
     3697    return $this->{store}->exists( address=>{web=>$web}); 
    36953698} 
    36963699 
     
    37093712    ASSERT( UNTAINTED($web),   'web is tainted' )   if DEBUG; 
    37103713    ASSERT( UNTAINTED($topic), 'topic is tainted' ) if DEBUG; 
    3711     return $this->{store}->topicExists( $web, $topic ); 
     3714    return $this->{store}->exists( address=>{web=>$web, topic=>$topic}); 
    37123715} 
    37133716 
     
    37543757Foswiki - The Free and Open Source Wiki, http://foswiki.org/ 
    37553758 
    3756 Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors 
     3759Copyright (C) 2008-2011 Foswiki Contributors. Foswiki Contributors 
    37573760are listed in the AUTHORS file in the root of this distribution. 
    37583761NOTE: Please extend that file, not this notice. 
  • branches/scratch/core/lib/Foswiki/Access/TopicACLAccess.pm

    r12153 r12543  
    2828    ASSERT( $session->isa('Foswiki') ) if DEBUG; 
    2929    my $this = bless( { session => $session }, $class ); 
     30     
     31    ASSERT(defined($this->{session})) if DEBUG; 
    3032 
    3133    return $this; 
     
    4648 
    4749sub haveAccess { 
     50    if ($_[$#_-1] eq 'dontload') { 
     51        #print STDERR "-------------say its ok, even if its not $_[$#_-1] => $_[$#_]\n"; 
     52        return 1 ; 
     53    } 
    4854    my ( $this, $mode, $cUID, $param1, $param2, $param3 ) = @_; 
    4955    $mode ||= 'VIEW'; 
    5056    $cUID ||= $this->{session}->{user}; 
     57     
     58    #print STDERR "cUID isa ".ref($cUID)."\n"; 
     59    ASSERT(ref($cUID) eq '') if DEBUG; 
     60     
     61    ASSERT(ref($this) eq 'Foswiki::Access::TopicACLAccess') if DEBUG; 
     62    ASSERT(defined($this->{session})) if DEBUG; 
     63 
    5164 
    5265    my $session = $this->{session}; 
     
    5871 
    5972        #scalar - treat as web, topic 
    60         $meta = Foswiki::Meta->load( $session, $param1, $param2 ); 
     73        $meta = Foswiki::Store::load(address=>{web=>$param1, topic=>$param2}); 
     74 
    6175        ASSERT(not defined($param3)) if DEBUG;  #attachment ACL not currently supported in traditional topic ACL 
    6276    } 
    6377    else { 
    6478        if ( ref($param1) eq 'Foswiki::Address' ) { 
    65             $meta = 
    66               Foswiki::Meta->load( $session, $param1->web(), $param1->topic() ); 
     79            $meta = Foswiki::Store::load(address=>$param1); 
    6780        } 
    6881        else { 
  • branches/scratch/core/lib/Foswiki/Address.pm

    r12542 r12543  
    7070#use Data::Dumper; 
    7171use constant TRACE  => 0;    # Don't forget to uncomment dumper 
    72 use constant TRACE2 => 0; 
     72use constant TRACE2 => 1; 
    7373 
    7474my %atomiseAs = ( 
     
    252252 
    253253sub new { 
    254     my ( $class, %opts ) = @_; 
     254    my $class = shift; 
    255255    my $this; 
    256  
     256     
     257    if (ref($_[0]) and $_[0]->isa('Foswiki::Address')) { 
     258#print STDERR "COPY CONCTRUCTOR ($class, $_[0])\n"; 
     259        #need a copy construtor  
     260        #TODO: Paul -  help? 
     261        $this = bless(             { 
     262                    webpath => $_[0]->{webpath}, 
     263                    web => $_[0]->web(), 
     264                    topic   => $_[0]->{topic}, 
     265                    tompath => $_[0]->{tompath}, 
     266                    rev     => $_[0]->{rev}, 
     267                }, $class ); 
     268        #$this->parse( $_[0]->{string} ); 
     269        return $this; 
     270    } 
     271     
     272    my %opts = @_; 
     273     
    257274    if ( $opts{string} ) { 
    258275        ASSERT( not $opts{topic} or ( $opts{webpath} and $opts{topic} ) ) 
     
    10041021 
    10051022sub stringify { 
     1023        return getPath(@_); 
     1024} 
     1025 
     1026 
     1027sub getPath { 
    10061028    my ( $this, %opts ) = @_; 
    10071029 
     
    11171139    my ( $this, $web ) = @_; 
    11181140 
    1119     ASSERT( $this->{web} or ref( $this->{webpath} ) eq 'ARRAY' ) if DEBUG; 
    1120     if ( scalar(@_) == 2 ) { 
     1141    ASSERT( scalar(@_) == 2  or (defined($this->{webpath}) and ref( $this->{webpath} ) eq 'ARRAY') ) if DEBUG; 
     1142    if ( scalar(@_) == 2  ) { 
    11211143        $this->webpath( [ split( /[\/\.]/, $web ) ] ); 
    11221144    } 
    1123     if ( not $this->{web} ) { 
     1145    if ( not $this->{web} and defined($this->{webpath} )) { 
    11241146        $this->{web} = join( '/', @{ $this->{webpath} } ); 
    11251147    } 
    1126  
     1148    ASSERT($this->{web}) if DEBUG; 
    11271149    return $this->{web}; 
    11281150} 
  • branches/scratch/core/lib/Foswiki/Meta.pm

    r12542 r12543  
    345345=cut 
    346346 
    347 sub new { 
     347sub OLDnew { 
    348348    my ( $class, $session, $web, $topic, $text ) = @_; 
    349  
     349die 'no'; 
    350350    if ( $session->isa('Foswiki::Meta') ) { 
    351  
     351#die 'ke'; 
    352352        # Prototype 
    353353        ASSERT( !defined($web) && !defined($topic) && !defined($text) ) 
     
    355355        return $class->new( $session->session, $session->web, $session->topic ); 
    356356    } 
     357 
     358    ASSERT(( caller(0) )[3] eq 'load') if DEBUG; 
     359    #die 'asdf'; 
     360     
    357361 
    358362    my $this = (ref($class) || $class)->SUPER::new( web=>$web, topic=>$topic ); 
     
    411415} 
    412416 
     417sub new { 
     418    my ( $class, $session, $web, $topic, $text ) = @_; 
     419 
     420    if ( $session->isa('Foswiki::Meta') ) { 
     421#die 'ke'; 
     422        # Prototype 
     423        ASSERT( !defined($web) && !defined($topic) && !defined($text) ) 
     424          if DEBUG; 
     425        return $class->new( $session->session, $session->web, $session->topic ); 
     426    } 
     427 
     428    #ASSERT(( caller(0) )[3] eq 'load') if DEBUG; 
     429    #die 'asdf'; 
     430     
     431 
     432    #my $this = (ref($class) || $class)->SUPER::new( web=>$web, topic=>$topic ); 
     433     
     434    my $metaObject = Foswiki::Store::load(address=>{web=>$web, topic=>$topic}); 
     435    return $metaObject; 
     436} 
     437 
     438#should only be called by the store.. 
     439sub NEWnew { 
     440    my $class = shift; 
     441    use Data::Dumper; 
     442    die Dumper(\@_) unless (defined($_[2])); 
     443    my %args = @_; 
     444     
     445    #copy the Foswiki::Address obj (which by this time it is :/) 
     446    my $this = (ref($class) || $class)->SUPER::new( $args{address} ); 
     447    #TODO: fix the Foswiki::Address constructor to allow inheritance 
     448    @{$this}{keys(%{$args{data}})} = values(%{$args{data}}) if (defined($args{data})); 
     449     
     450    #TODO: remove this. 
     451    $this->{_session} = $Foswiki::Plugins::SESSION; 
     452    # Index keyed on top level type mapping entry names to their 
     453    # index within the data array. 
     454    $this->{_indices} = undef; 
     455    $this->{FILEATTACHMENT} = []; 
     456     
     457    #die "-complete NEWnew --- = ".Dumper($this)."\n"; 
     458     
     459    return $this; 
     460} 
     461 
     462 
    413463=begin TML 
    414464 
     
    548598    #if its an intentional ref to an object, please add it to the undef's above. 
    549599 
    550 #SMELL: Sven noticed during development that something is adding a $this->{store} to a meta obj - havn't found it yet 
     600#SMELL: Sven noticed during development that something is adding a Foswiki::Store to a meta obj - havn't found it yet 
    551601#ASSERT(not defined($this->{store})) if DEBUG; 
    552602 
     
    570620sub session { 
    571621    return $_[0]->{_session}; 
    572 } 
    573  
    574 =begin TML 
    575  
    576 ---++ ObjectMethod web([$name]) 
    577    * =$name= - optional, change the web name in the object 
    578       * *Since* 28 Nov 2008 
    579 Get/set the web name associated with the object. 
    580  
    581 =cut 
    582  
    583 sub web { 
    584     my ( $this, $web ) = @_; 
    585     $this->{web} = $web if defined $web; 
    586     return $this->{web}; 
    587 } 
    588  
    589 =begin TML 
    590  
    591 ---++ ObjectMethod topic([$name]) 
    592    * =$name= - optional, change the topic name in the object 
    593       * *Since* 28 Nov 2008 
    594 Get/set the topic name associated with the object. 
    595  
    596 =cut 
    597  
    598 sub topic { 
    599     my ( $this, $topic ) = @_; 
    600     $this->{topic} = $topic if defined $topic; 
    601     return $this->{topic}; 
    602622} 
    603623 
     
    612632=cut 
    613633 
    614 sub getPath { 
     634sub OLDgetPath { 
    615635    my $this = shift; 
    616636    my $path = $this->{web}; 
     
    708728        $this->addDependency(); 
    709729 
    710         return $this->{_session}->{store} 
    711           ->exists(address=>$this); 
     730        return Foswiki::Store->exists(address=>$this); 
    712731    } 
    713732    elsif ( defined $this->{web} ) { 
    714         return $this->{_session}->{store}->exists(address=> $this ); 
     733        return Foswiki::Store->exists(address=> $this ); 
    715734    } 
    716735    else { 
     
    821840    # Validate that template web exists, or error should be thrown 
    822841    if ($templateWeb) { 
    823         unless ( $session->exists(address=>$templateWeb) ) { 
     842        unless ( Foswiki::Store->exists(address=>{web=>$templateWeb}) ) { 
    824843            throw Error::Simple( 
    825844                'Template web ' . $templateWeb . ' does not exist' ); 
     
    830849    my $prefsTopicObject; 
    831850    if ( 
    832         !$session->exists(address=>[ 
    833             $this->{web}, $Foswiki::cfg{WebPrefsTopicName} 
    834         ] 
     851        !Foswiki::Store->exists(address=>{web=> 
     852            $this->{web}, topic=>$Foswiki::cfg{WebPrefsTopicName} } 
    835853        ) 
    836854      ) 
    837855    { 
    838856        my $prefsText = 'Preferences'; 
    839         $prefsTopicObject = 
    840           $this->new( $this->{_session}, $this->{web}, 
    841             $Foswiki::cfg{WebPrefsTopicName}, $prefsText ); 
     857        $prefsTopicObject = Foswiki::Store::create(address=>{web=>$this->{web}, 
     858            topic=>$Foswiki::cfg{WebPrefsTopicName}}, data=>{_text=>$prefsText} ); 
    842859        $prefsTopicObject->save(); 
    843860    } 
     
    913930sub query { 
    914931    my ( $query, $inputTopicSet, $options ) = @_; 
    915     return $Foswiki::Plugins::SESSION->{store} 
    916       ->query( $query, $inputTopicSet, $Foswiki::Plugins::SESSION, $options ); 
     932    return Foswiki::Store->query( $query, $inputTopicSet, $Foswiki::Plugins::SESSION, $options ); 
    917933} 
    918934 
     
    934950    # Works on the root, so {web} may be undef 
    935951    ASSERT( !$this->{topic}, 'this object may not contain webs' ) if DEBUG; 
    936     return $this->{_session}->{store}->eachWeb( $this, $all ); 
     952    return Foswiki::Store->eachWeb( address=>$this, all=>$all ); 
    937953 
    938954} 
     
    956972        return new Foswiki::ListIterator( [] ); 
    957973    } 
    958     return $this->{_session}->{store}->eachTopic($this); 
     974    return Foswiki::Store->eachTopic(address=>$this); 
    959975} 
    960976 
     
    976992    ASSERT( $this->{web} && $this->{topic}, 'this is not a topic object' ) 
    977993      if DEBUG; 
    978     return $this->{_session}->{store}->eachAttachment($this); 
     994    return Foswiki::Store->eachAttachment(address=>$this); 
    979995} 
    980996 
     
    9991015    ASSERT( $this->{web} && !$this->{topic}, 'this is not a web object' ) 
    10001016      if DEBUG; 
    1001     return $this->{_session}->{store}->eachChange( $this, $time ); 
     1017    return Foswiki::Store->eachChange( address=>$this, from=>$time, to=>time()); 
    10021018} 
    10031019 
    10041020############# TOPIC METHODS ############# 
    10051021 
    1006 =begin TML 
    1007  
    1008 ---++ ObjectMethod loadVersion($rev) -> $version 
    1009  
    1010 Load the object from the store. The object must not be already loaded 
    1011 with a different rev (verified by an ASSERT) 
    1012  
    1013 See =getLoadedRev= to determine what revision is currently being viewed. 
    1014    * =$rev= - revision to load. If undef, 0, '' or > max available rev, will 
    1015      load the latest rev. If the revision is in range but does not exist, 
    1016      then will return an unloaded meta object (getLoadedRev() will be undef) 
    1017  
    1018 Returns the version identifier for the loaded revision. (and undef if it failed to load) 
    1019  
    1020 WARNING: see notes on revision numbers under =getLoadedRev= 
    1021  
    1022 =cut 
    1023  
    1024 sub loadVersion { 
    1025     my ( $this, $rev ) = @_; 
    1026  
    1027     return unless $this->{topic}; 
    1028  
    1029     # If no specific rev was requested, check that the latest rev is 
    1030     # loaded. 
    1031     if ( !defined $rev || !$rev ) { 
    1032  
    1033         # Trying to load the latest 
    1034         if ( $this->{_latestIsLoaded} ) { 
    1035  
    1036             #TODO: these asserts trip up Comment Plugin 
    1037             #ASSERT(defined($this->{_loadedRev})) if DEBUG; 
    1038             #ASSERT($rev == $this->{_loadedRev}) if DEBUG; 
    1039             return; 
    1040         } 
    1041         ASSERT( not( $this->{_loadedRev} ) ) if DEBUG; 
    1042     } 
    1043     elsif ( defined( $this->{_loadedRev} ) ) { 
    1044  
    1045         # Cannot load a different rev into an already-loaded 
    1046         # Foswiki::Meta object 
    1047         $rev = -1 unless defined $rev; 
    1048         ASSERT( 0, "Attempt to reload $rev over version $this->{_loadedRev}" ) 
    1049             if DEBUG; 
    1050     } 
    1051  
    1052     # Is it already loaded? 
    1053     ASSERT( !($rev) or $rev =~ /^\s*\d+\s*/ ) if DEBUG;    # looks like a number 
    1054     return $this->{_loadedRev} 
    1055       if ( $rev && $this->{_loadedRev} && $rev == $this->{_loadedRev} ); 
    1056  
    1057     ASSERT( not( $this->{_loadedRev} ) ) if DEBUG; 
    1058  
    1059     ( $this->{_loadedRev}, $this->{_latestIsLoaded} ) = 
    1060       $this->{_session}->{store}->readTopic( $this, $rev ); 
    1061     if ( defined( $this->{_loadedRev} ) ) { 
    1062  
    1063         # Make sure text always has a value once loadVersion has been called 
    1064         # once. 
    1065         $this->{_text} = '' unless defined $this->{_text}; 
    1066  
    1067         $this->addDependency(); 
    1068     } 
    1069     else { 
    1070  
    1071         #we didn't load, so how could it be latest? 
    1072         ASSERT( not $this->{_latestIsLoaded} ) if DEBUG; 
    1073     } 
    1074  
    1075     return $this->{_loadedRev}; 
    1076 } 
    10771022 
    10781023=begin TML 
     
    10891034sub text { 
    10901035    my ( $this, $val ) = @_; 
     1036 
    10911037    ASSERT( $this->{web} && $this->{topic}, 'this is not a topic object' ) 
    10921038      if DEBUG; 
    10931039    if ( defined($val) ) { 
    10941040        $this->{_text} = $val; 
    1095     } 
    1096     else { 
    1097  
    1098         # Lazy load. Reload with no params will reload the _loadedRev, 
    1099         # or load the latest if that is not defined. 
    1100         $this->loadVersion() unless defined( $this->{_text} ); 
    11011041    } 
    11021042    return $this->{_text}; 
     
    12611201        } 
    12621202        else { 
     1203            ASSERT(ref($data) eq 'ARRAY', $data) if DEBUG; 
    12631204            return $data->[0]; 
    12641205        } 
     
    13771318        return if $type =~ /^_/; 
    13781319        my @data; 
     1320         
     1321        #HACK. DELETE and replace with serialise only registered tpes? 
     1322        return unless (ref($other->{$type}) eq 'ARRAY');    #data from Foswiki::Address 
     1323        return if ($type eq 'webpath'); 
     1324 
     1325         
    13791326        foreach my $item ( @{ $other->{$type} } ) { 
    13801327            if ( !$filter 
     
    15071454 
    15081455        # Delegate to the store 
    1509         $info = $this->{_session}->{store}->getVersionInfo($this); 
     1456        $info = Foswiki::Store->getVersionInfo(address=>$this); 
    15101457 
    15111458        # cache the result 
     
    19041851    my $newRev; 
    19051852    try { 
    1906         $newRev = $this->saveAs( $this->{web}, $this->{topic}, %opts ); 
     1853        $newRev = $this->__internal_save( %opts ); 
    19071854    } 
    19081855    catch Error::Simple with { 
     
    19371884=begin TML 
    19381885 
    1939 ---++ ObjectMethod saveAs( $web, $topic, %options  ) -> $rev 
     1886---++ ObjectMethod __internal_save( %options  ) -> $rev 
    19401887 
    19411888Save the current topic to a store location. Only works on topics. 
    19421889*without* invoking plugins handlers. 
    1943    * =$web.$topic= - where to move to 
    19441890   * =%options= - Hash of options, may include: 
    19451891      * =forcenewrevision= - force an increment in the revision number, 
     
    19621908# SMELL: arguably save should only be permitted if the loaded rev 
    19631909# of the object is the same as the latest rev. 
    1964 sub saveAs { 
     1910sub __internal_save { 
    19651911    my $this = shift; 
    19661912    ASSERT( $this->{web} && $this->{topic}, 'this is not a topic object' ) 
    19671913      if DEBUG; 
    1968  
    1969     my $newWeb   = shift; 
    1970     my $newTopic = shift; 
    19711914    ASSERT( scalar(@_) % 2 == 0 ) if DEBUG; 
    19721915    my %opts = @_; 
    19731916    my $cUID = $opts{author} || $this->{_session}->{user}; 
    1974     $this->{web}   = $newWeb   if $newWeb; 
    1975     $this->{topic} = $newTopic if $newTopic; 
    19761917    ASSERT( $this->{web} && $this->{topic}, 'this is not a topic object' ) 
    19771918      if DEBUG; 
     
    19811922        # Don't verify web existance for WebPreferences, as saving 
    19821923        # WebPreferences creates the web. 
    1983         unless ( $this->{_session}->{store}->exists(address=> $this->{web}  )) { 
     1924        unless ( Foswiki::Store->exists(address=> {web=> $this->web()}  )) { 
    19841925            throw Error::Simple( 'Unable to save topic ' 
    19851926                  . $this->{topic} 
     
    19911932 
    19921933    $this->_atomicLock($cUID); 
    1993     my $i = $this->{_session}->{store}->getRevisionHistory($this); 
     1934    my $i = Foswiki::Store->getRevisionHistory(address=>$this); 
    19941935    my $currentRev = $i->hasNext() ? $i->next() : 1; 
    19951936    try { 
     
    19981939            # See if we want to replace the existing top revision 
    19991940            my $mtime1 = 
    2000               $this->{_session}->{store} 
    2001               ->getApproxRevTime( $this->{web}, $this->{topic} ); 
     1941              Foswiki::Store->getApproxRevTime( address=>$this ); 
    20021942            my $mtime2 = time(); 
    20031943            my $dt     = abs( $mtime2 - $mtime1 ); 
    20041944            if ( $dt <= $Foswiki::cfg{ReplaceIfEditedAgainWithin} ) { 
    2005                 my $info = $this->{_session}->{store}->getVersionInfo($this); 
     1945                my $info = Foswiki::Store->getVersionInfo(address=>$this); 
    20061946 
    20071947                # same user? 
     
    20141954                    $info->{date} = $opts{forcedate} || time(); 
    20151955                    $this->setRevisionInfo(%$info); 
    2016                     $this->{_session}->{store}->repRev( $this, $cUID, %opts ); 
     1956                    Foswiki::Store->repRev( address=>$this, cuid=>$cUID, %opts ); 
    20171957                    $this->{_loadedRev} = $currentRev; 
    20181958                    return $currentRev; 
     
    20201960            } 
    20211961        } 
    2022         my $nextRev = $this->{_session}->{store}->getNextRevision($this); 
     1962        my $nextRev = Foswiki::Store->getNextRevision(address=>$this); 
    20231963        $this->setRevisionInfo( 
    20241964            date => $opts{forcedate} || time(), 
     
    20281968 
    20291969        my $checkSave = 
    2030           $this->{_session}->{store}->saveTopic( $this, $cUID, \%opts ); 
     1970          Foswiki::Store->save( address=>$this, cuid=>$cUID, %opts ); 
    20311971        ASSERT( $checkSave == $nextRev, "$checkSave != $nextRev" ) if DEBUG; 
    20321972        $this->{_loadedRev} = $nextRev; 
     
    20571997        while (1) { 
    20581998            my ( $user, $time ) = 
    2059               $this->{_session}->{store}->atomicLockInfo($this); 
     1999              Foswiki::Store->atomicLockInfo(address=>$this); 
    20602000            last if ( !$user || $cUID eq $user ); 
    20612001            $logger->log( 'warning', 
     
    20712011                $logger->log( 'warning', 
    20722012                    $cUID . " broke ${user}s lock on " . $this->getPath() ); 
    2073                 $this->{_session}->{store}->atomicUnlock( $this, $cUID ); 
     2013                Foswiki::Store->atomicUnlock( address=>$this, cuid=>$cUID ); 
    20742014                last; 
    20752015            } 
     
    20802020 
    20812021        # Topic 
    2082         $this->{_session}->{store}->atomicLock( $this, $cUID ); 
     2022        Foswiki::Store->atomicLock( address=>$this, cuid=>$cUID ); 
    20832023    } 
    20842024    else { 
     
    21032043    my ( $this, $cUID ) = @_; 
    21042044    if ( $this->{topic} ) { 
    2105         $this->{_session}->{store}->atomicUnlock($this); 
     2045        Foswiki::Store->atomicUnlock(address=>$this); 
    21062046    } 
    21072047    else { 
     
    21762116                dontlog => 1, # no statistics 
    21772117            ); 
    2178             $from->{_session}->{store}->moveTopic( $from, $to, $cUID ); 
     2118            Foswiki::Store->moveTopic( from=>$from, address=>$to, cuid=>$cUID ); 
    21792119            $to->loadVersion(); 
    21802120            ASSERT( defined($to) and defined( $to->{_loadedRev} ) ) if DEBUG; 
     
    21912131 
    21922132        # Move web 
    2193         ASSERT( !$this->{_session}->{store}->exists(address=> $to ), 
     2133        ASSERT( !Foswiki::Store->exists(address=> $to ), 
    21942134            "$to->{web} does not exist" ) 
    21952135          if DEBUG; 
    21962136        $this->_atomicLock($cUID); 
    2197         $this->{_session}->{store}->moveWeb( $this, $to, $cUID ); 
     2137        Foswiki::Store->moveWeb( from=>$this, address=>$to, cuid=>$cUID ); 
    21982138 
    21992139        # No point in unlocking $this - it's moved! 
     
    22322172    $this->_atomicLock($cUID); 
    22332173    try { 
    2234         $rev = $this->{_session}->{store}->delRev( $this, $cUID ); 
     2174        $rev = Foswiki::Store->delRev( address=>$this, cuid=>$cUID ); 
    22352175    } 
    22362176    finally { 
     
    22952235 
    22962236    try { 
    2297         $this->{_session}->{store}->repRev( $this, $cUID, @_ ); 
     2237        Foswiki::Store->repRev( address=>$this, cuid=>$cUID, @_ ); 
    22982238    } 
    22992239    finally { 
     
    23392279#    } 
    23402280 
    2341     return $this->{_session}->{store}->getRevisionHistory( $this, $attachment ); 
     2281    return Foswiki::Store->getRevisionHistory( address=>$this, attachment=>$attachment ); 
    23422282} 
    23432283 
     
    24212361sub removeFromStore { 
    24222362    my ( $this, $attachment ) = @_; 
    2423     my $store = $this->{_session}->{store}; 
     2363     
    24242364    ASSERT( $this->{web}, 'this is not a removable object' ) if DEBUG; 
    24252365 
    2426     if ( !$store->exists(address=> $this->{web}  )) { 
     2366    if ( !Foswiki::Store->exists(address=> {web=>$this->{web}}  )) { 
    24272367        throw Error::Simple( 'No such web ' . $this->{web} ); 
    24282368    } 
    24292369    if ( $this->{topic} 
    2430         && !$store->exists(address=>[ $this->{web}, $this->{topic} ] )) 
     2370        && !Foswiki::Store->exists(address=>$this )) 
    24312371    { 
    24322372        throw Error::Simple( 
     
    24422382    } 
    24432383 
    2444     $store->remove( $this->{_session}->{user}, $this, $attachment ); 
     2384    Foswiki::Store->remove( address=>$this, attachment=>$attachment ); 
    24452385} 
    24462386 
     
    24682408    ASSERT( $this->{web} && $this->{topic}, 'this is not a topic object' ) 
    24692409      if DEBUG; 
    2470     return $this->{_session}->{store} 
    2471       ->getRevisionDiff( $this, $rev2, $contextLines ); 
     2410    return Foswiki::Store->getRevisionDiff( from=>$this, address=>$rev2, contextLines=>$contextLines ); 
    24722411} 
    24732412 
     
    24872426    ASSERT( $this->{web} && $this->{topic}, 'this is not a topic object' ) 
    24882427      if DEBUG; 
    2489     return $this->{_session}->{store}->getRevisionAtTime( $this, $time ); 
     2428    return Foswiki::Store->getRevisionAtTime( address=>$this, time=>$time ); 
    24902429} 
    24912430 
     
    25102449        taken   => $t 
    25112450    }; 
    2512     return $this->{_session}->{store}->setLease( $this, $lease ); 
     2451    return Foswiki::Store->setLease( address=>$this, length=>$lease ); 
    25132452} 
    25142453 
     
    25302469    ASSERT( $this->{web} && $this->{topic}, 'this is not a topic object' ) 
    25312470      if DEBUG; 
    2532     return $this->{_session}->{store}->getLease($this); 
     2471    return Foswiki::Store->getLease(address=>$this); 
    25332472} 
    25342473 
     
    25512490          . ' this is not a topic object' 
    25522491    ) if DEBUG; 
    2553     $this->{_session}->{store}->setLease($this); 
     2492    Foswiki::Store->setLease(address=>$this); 
    25542493} 
    25552494 
     
    25872526        # Clean up spurious leases that may have been left behind 
    25882527        # during cancelled topic creation 
    2589         $this->{_session}->{store}->removeSpuriousLeases( $this->getPath() ) 
     2528        Foswiki::Store->removeSpuriousLeases( address=>$this ) 
    25902529          if $this->getPath(); 
    25912530    } 
     
    26162555      if DEBUG; 
    26172556 
    2618     return $this->{_session}->{store} 
    2619       ->getAttachmentVersionInfo( $this, $fromrev, $attachment ); 
     2557    return Foswiki::Store 
     2558      ->getAttachmentVersionInfo( address=>$this, rev=>$fromrev, attachment=>$attachment ); 
    26202559} 
    26212560 
     
    27682707        my $error; 
    27692708        try { 
    2770             $this->{_session}->{store} 
    2771               ->saveAttachment( $this, $opts{name}, $opts{stream}, 
    2772                 $opts{author} || $this->{_session}->{user}, $opts{comment} ); 
     2709            Foswiki::Store 
     2710              ->saveAttachment( address=>$this, attachment=>$opts{name}, stream=>$opts{stream}, 
     2711                cuid=>($opts{author} || $this->{_session}->{user}) ); 
    27732712        } 
    27742713        finally { 
     
    28392778    ASSERT( $this->{web} && $this->{topic}, 'this is not a topic object' ) 
    28402779      if DEBUG; 
    2841     return $this->{_session}->{store}->attachmentExists( $this, $name ); 
     2780    return Foswiki::Store->attachmentExists( address=>$this, attachment=>$name ); 
    28422781} 
    28432782 
     
    28912830 
    28922831    return 
    2893       return $this->{_session}->{store} 
    2894       ->testAttachment( $this, $attachment, $test ); 
     2832      return Foswiki::Store 
     2833      ->testAttachment( address=>$this, attachment=>$attachment, test=>$test ); 
    28952834} 
    28962835 
     
    29242863      if DEBUG; 
    29252864 
    2926     return $this->{_session}->{store} 
    2927       ->openAttachment( $this, $attachment, $mode, @opts ); 
     2865    return Foswiki::Store 
     2866      ->openAttachment( address=>$this, attachment=>$attachment, mode=>$mode, @opts ); 
    29282867 
    29292868} 
     
    29582897 
    29592898    try { 
    2960         $this->{_session}->{store} 
    2961           ->moveAttachment( $this, $name, $to, $newName, $cUID ); 
     2899        Foswiki::Store 
     2900          ->moveAttachment( from=>$this, fromattachment=>$name, address=>$to, toattachment=>$newName, cuid=>$cUID ); 
    29622901 
    29632902        # Modify the cache of the old topic 
     
    30482987 
    30492988    try { 
    3050         $from->{_session}->{store} 
    3051           ->copyAttachment( $from, $name, $to, $newName, $cUID ); 
     2989        Foswiki::Store 
     2990          ->copyAttachment( from=>$from, fromattachment=>$name, address=>$to, toattachment=>$newName, cuid=>$cUID ); 
    30522991 
    30532992        # Add file attachment to new topic by copying the old one 
  • branches/scratch/core/lib/Foswiki/Prefs.pm

    r12404 r12543  
    137137    my $this       = shift; 
    138138 
    139     my $metaObject = Foswiki::Meta->new( $this->{session}, @_ ); 
     139    return undef unless (Foswiki::Store::exists(address=>{web=>$_[0], topic=>$_[1]})); 
     140    my $metaObject = Foswiki::Store::load(address=>{web=>$_[0], topic=>$_[1]}); 
    140141    my $path = $metaObject->getPath(); 
    141142    unless ( exists $this->{paths}{$path} ) { 
     
    160161        $subWeb .= $_; 
    161162        $back = $this->_getBackend( $subWeb, $Foswiki::cfg{WebPrefsTopicName} ); 
    162         $stack->newLevel($back); 
     163        $stack->newLevel($back) if (defined($back)); 
    163164    } 
    164165} 
     
    220221    my ( $this, $topicObject ) = @_; 
    221222 
    222     my $path = $topicObject->getPath(); 
    223  
     223    #my $path = $topicObject->getPath(); 
    224224    #    $topicObject->session->logger->log( 'debug', 
    225225    #        "Loading preferences for $path\n" ) 
     
    275275        $subWeb .= $_; 
    276276        $back = $this->_getBackend( $subWeb, $Foswiki::cfg{WebPrefsTopicName} ); 
    277         $stack->newLevel($back); 
     277        $stack->newLevel($back) if (defined($back)); 
    278278    } 
    279279    $back = $this->_getBackend( $web, $topic ); 
    280     $stack->newLevel($back); 
     280    $stack->newLevel($back) if (defined($back)); 
    281281    $stack->newLevel( Foswiki::Prefs::HASH->new() ); 
    282282 
     
    343343    my ( $this, $wn ) = @_; 
    344344    my $back = $this->_getBackend( $Foswiki::cfg{UsersWebName}, $wn ); 
    345     $this->{main}->newLevel($back); 
     345    $this->{main}->newLevel($back) if (defined($back)); 
    346346} 
    347347 
     
    375375          ->normalizeWebTopicName( undef, $Foswiki::cfg{LocalSitePreferences} ); 
    376376        my $back = $this->_getBackend( $web, $topic ); 
    377         $this->{main}->newLevel($back); 
     377        $this->{main}->newLevel($back) if (defined($back)); 
    378378    } 
    379379} 
  • branches/scratch/core/lib/Foswiki/Serialise/Embedded.pm

    r12339 r12543  
    1919use Assert; 
    2020 
     21#debug! 
     22    use Data::Dumper; 
     23 
    2124=begin TML 
    2225 
     
    4144#really awkward - setEmbeddedStoreForm interleaves reading from text and calling Meta calls to update cache information 
    4245#need to separate these out in a performant way. 
    43 sub read { 
    44     die 'not implemented'; 
     46sub DELETEMEread { 
    4547    my $module = shift; 
    4648    my ( $session, $result ) = @_; 
    4749 
    48     ASSERT( $result->isa('Foswiki::Meta') ) if DEBUG; 
    49     return setEmbeddedStoreForm($result); 
     50    my @elements = split(/^(%META:.*)%\n/, $result);    
     51 
     52    print STDERR "-elements --- = ".Dumper(@elements)."\n"; 
     53 
     54 
     55    #split(/(\%META:.*\%\n)/, $result); 
     56    my %output; 
     57    foreach my $element (@elements) { 
     58            #1.0 compatibility 
     59            #$text =~ s/^%META:([^{]+){(.*)}%\n/ ..... /gem 
     60            #$text =~ s/^(%META:([^{]+){(.*)}%\n)/ ..... /gem 
     61         
     62        #if ($element =~ /%META:([A..Z0..9]*)({.*})%/ ) { 
     63        if ($element =~ /^%META/ ) { 
     64            #TODO: find the marco parsing code? 
     65            print STDERR "Meta $1 - params $2\n" 
     66        } else { 
     67            print STDERR "text - $element\n"; 
     68            ASSERT(not defined($output{text})) if DEBUG; 
     69            $output{text} = $element; 
     70        } 
     71    } 
     72    print STDERR "-complete --- = ".Dumper(%output)."\n"; 
     73    die; 
     74    return \%output; 
     75} 
     76sub read { 
     77    my $module = shift; 
     78    my ( $session, $result ) = @_; 
     79 
     80    my %output; 
     81    $result =~ s/^%META:([^{]+){(.*)}%\n/push(@{$output{$1}}, _readKeyValues($2));''/gem; 
     82     
     83    #correct the META for which there can be only one. (ignore all but first) 
     84    map { 
     85         $output{$_} = $output{$_}[0] if (defined($output{$_})); 
     86     } qw(TOPICINFO TOPICPARENT TOPICMOVED); 
     87     
     88    $output{_text} = $result; 
     89 
     90    #die "-complete --- = ".Dumper(\%output)."\n"; 
     91 
     92    return \%output; 
    5093} 
    5194 
     
    71114    my $this = shift; 
    72115 
    73     ASSERT( $this->{_web} && $this->{_topic}, 'this is not a topic object' ) 
     116    ASSERT( $this->{web} && $this->{topic}, 'this is not a topic object' ) 
    74117      if DEBUG; 
    75118    $this->{_text} ||= ''; 
     
    130173        my $data = $this->{$type}; 
    131174        next if !defined $data; 
     175         
     176        #HACK. DELETE and replace with serialise only registered tpes? 
     177        next unless (ref($data) eq 'ARRAY');    #data from Foswiki::Address 
     178        next if ($type eq 'webpath'); 
     179         
    132180        foreach my $item (@$data) { 
    133181            next if ($item =~ /^_/ ); 
     
    180228} 
    181229 
     230=begin TML 
     231 
     232---++ StaticMethod dataDecode( $encoded ) -> $decoded 
     233 
     234Decode escapes in a string that was encoded using dataEncode 
     235 
     236The encoding has to be exported because Foswiki (and plugins) use 
     237encoded field data in other places e.g. RDiff, mainly as a shorthand 
     238for the properly parsed meta object. Some day we may be able to 
     239eliminate that.... 
     240 
     241=cut 
     242 
     243sub dataDecode { 
     244    my $datum = shift; 
     245 
     246    $datum =~ s/%([\da-f]{2})/chr(hex($1))/gei; 
     247    return $datum; 
     248} 
     249 
     250 
     251# STATIC Build a hash by parsing name=value comma separated pairs 
     252# SMELL: duplication of Foswiki::Attrs, using a different 
     253# system of escapes :-( 
     254sub _readKeyValues { 
     255    my ($args) = @_; 
     256    my %res; 
     257 
     258    # Format of data is name='value' name1='value1' [...] 
     259    $args =~ s/\s*([^=]+)="([^"]*)"/ 
     260      $res{$1} = dataDecode( $2 ), ''/ge; 
     261 
     262    return \%res; 
     263} 
     264 
    1822651; 
    183266__END__ 
  • branches/scratch/core/lib/Foswiki/Store.pm

    r12541 r12543  
    7474 
    7575sub changeDefaultUser { 
    76     $singleton->{cuid} = shift; 
     76    #pick the last param, so that we can be class or object called. 
     77    $singleton->{cuid} = $_[$#_]; 
     78 
     79    ASSERT(not defined($singleton->{cuid}) or ref($singleton->{cuid}) eq '') if DEBUG; 
     80    die 'snow '.ref($singleton->{cuid}) if (ref($singleton->{cuid}) ne ''); 
     81     
    7782    ASSERT((not defined($singleton->{cuid})) 
    7883                or  
     
    101106 
    102107sub load { 
    103     return template_function( 'load', @_ ); 
     108    shift if ((ref($_[0]) eq 'Foswiki::Store') or ($_[0] eq 'Foswiki::Store')); 
     109     
     110    #default cuid from the singleton 
     111    my %args = ( cuid=>$singleton->{cuid}, @_ ); 
     112    $args{functionname} = 'load'; 
     113     
     114    #print STDERR ".cUID isa ".ref($args{cuid})." ($args{cuid}) - default (".ref($singleton->{cuid}).")\n"; 
     115    #ASSERT(not defined($args{cuid}) or ref($args{cuid}) eq '') if DEBUG; 
     116    #die 'here' if (ref($args{cuid}) ne ''); 
     117 
     118    my $access_type = $args{writeable} ? 'CHANGE' : 'VIEW'; 
     119 
     120    my $result; 
     121    $args{address} = $singleton->getResourceAddressOrCachedResource($args{address}); 
     122    die "recursion? - load(".$singleton->{count}{load}{$args{address}->getPath()}.") ".$args{address}->getPath() if ($singleton->{count}{load}{$args{address}->getPath()}++ > 10); 
     123 
     124    print STDERR "-call: load ".($args{address}->getPath())."\n"; 
     125 
     126 
     127    if (ref($args{address}) eq 'Foswiki::Meta') { 
     128        $result = $args{address}; 
     129    } else { 
     130 
     131    #see if we are _able_ to test permissions using just an unloaded topic, if not, fall through to load&then test 
     132        throw AccessException( $singleton->{access}->getReason() ) 
     133          if (  defined( $args{cuid} )  and  
     134                not ($singleton->{access} 
     135              ->haveAccess( $access_type, $args{cuid}, $args{address},  
     136                  dontload => 1 ) )); 
     137           
     138#       if ( defined( $args{from} ) ) { 
     139# 
     140#            #load will throw exceptions if things go wrong 
     141#            $args{from} = load( address => $args{from} ) 
     142#              unless ( $args{from}->isa('Foswiki::Address') ); 
     143#        } 
     144 
     145    #$cfg::Foswiki{Stores} is an ordered list, managed by configure that prioritises the cache stores first. 
     146        foreach my $impl ( @{ $singleton->{stores} } ) { 
     147 
     148    #the impl is also able to throw exceptions - as there might be a store based permissions impl 
     149            if (not defined($impl->{impl})) { 
     150                eval "require ".$impl->{module}; 
     151                ASSERT( !$@, $@ ) if DEBUG; 
     152                $impl->{impl} = $Foswiki::cfg{Store}{Implementation}->new(); 
     153            } 
     154            #$impl->{impl} ||= $impl.'::new'( store => $impl ) || next; 
     155            $result = $impl->{impl}->load(%args); 
     156            last if ( defined($result) ); 
     157        } 
     158        if (ref($result) eq 'Foswiki::Meta') { 
     159            #ok, we have a resource object that actually exists in a store 
     160            $singleton->cacheResource(%args, return=>$result); 
     161        } 
     162         
     163        if ( not defined($result) and $args{create} ) { 
     164            $result = create(%args); 
     165        } 
     166 
     167        throw DoesNotExist(%args) 
     168          unless ( defined($result) ); 
     169      } 
     170 
     171    if (ref($result) eq 'Foswiki::Meta') { 
     172        #now to make sure we're allowed to give it to the user. 
     173 
     174        foreach my $impl ( @{ $singleton->{stores} } ) { 
     175            if (not defined($impl->{impl})) { 
     176                eval "require ".$impl->{module}; 
     177                ASSERT( !$@, $@ ) if DEBUG; 
     178                $impl->{impl} = $Foswiki::cfg{Store}{Implementation}->new(); 
     179            } 
     180 
     181    #a listener for load events. 
     182    #TODO: kill this and replace with call to logger, which stores can choose to consume! 
     183            $impl->{impl}->log( %args, return => $result ); 
     184        } 
     185 
     186    #can't do any better with the __current__ ACL impl, but there should be a call before the readData for real store-fastening 
     187        ASSERT(ref($args{cuid}) eq ''); 
     188        #print STDERR "..cUID isa ".ref($args{cuid})." ($args{cuid})\n"; 
     189 
     190        throw AccessException( $singleton->{access}->getReason() ) 
     191          if (  defined( $args{cuid} )  and  
     192                not ($singleton->{access} 
     193              ->haveAccess( $access_type, $args{cuid}, $result ) )); 
     194    } 
     195           
     196    $singleton->{count}{load}{$args{address}->getPath()}--;           
     197 
     198    return $result; 
    104199} 
    105200 
     
    117212 
    118213returns an object of the appropriate type from the Foswiki::Object:: hieracy 
    119  
    120 TODO: note that most of the methods here will have the same codepath as load(),  
    121 so it might be better to write it all as a switchboard.. 
    122214 
    123215=cut 
     
    152244=pod 
    153245 
    154 =head2 ClassMethod delete(address=>$address, cuid=>$cuid, -> success? 
     246=head2 ClassMethod remove(address=>$address, cuid=>$cuid, -> success? 
    155247   * =address= - (required) Address - can be a specific revision, in which case it requests the store to =delRev= 
    156248   * cuid=>$cuid (canonical user id) - if undefined, presume 'admin' (or no perms check) access 
     
    162254=cut 
    163255 
    164 sub delete { 
    165     return template_function( 'delete', @_ ); 
     256sub remove { 
     257    return template_function( 'remove', @_ ); 
    166258} 
    167259 
     
    398490=pod 
    399491 
     492=head2 ClassMethod eachWeb( address=>$address) -> $iterator 
     493 
     494Get an iterator over the list of all elements of type '$type' that are sub elements of the addressed one 
     495 
     496=cut 
     497 
     498sub eachWeb { 
     499    return template_function( 'eachWeb', @_ ); 
     500} 
     501 
     502=pod 
     503 
     504=head2 ClassMethod eachTopic( address=>$address) -> $iterator 
     505 
     506Get an iterator over the list of all elements of type '$type' that are sub elements of the addressed one 
     507 
     508=cut 
     509 
     510sub eachTopic { 
     511    return template_function( 'eachTopic', @_ ); 
     512} 
     513 
     514=pod 
     515 
    400516=head2 ClassMethod query($query, $inputTopicSet, $session, \%options) -> $outputTopicSet 
    401517 
     
    457573=pod 
    458574 
    459 =head2 ClassMethod setLease( address=>$address, cuid=>$cuid, $length ) 
     575=head2 ClassMethod setLease( address=>$address, cuid=>$cuid, length=>$length ) 
    460576 
    461577   * =$topicObject= - Foswiki::Meta topic object 
     
    493609sub template_function { 
    494610    my $functionname = shift; 
    495     shift if (ref($_[0]) eq 'Foswiki::Store'); 
     611    shift if ((ref($_[0]) eq 'Foswiki::Store') or ($_[0] eq 'Foswiki::Store')); 
    496612     
    497613    #default cuid from the singleton 
    498614    my %args = ( cuid=>$singleton->{cuid}, @_ ); 
    499615    $args{functionname} = $functionname; 
    500  
    501     #TODO: or can I delay this to the point where its not needed at all? 
    502     $args{address} = Foswiki::Address->new( $args{address} ) 
    503       if (ref($args{address}) eq '');   #justa string/scalar 
    504     $args{address} = Foswiki::Address->new( @{$args{address}} ) 
    505       if (ref($args{address}) eq 'ARRAY'); 
     616     
     617    #print STDERR ".cUID isa ".ref($args{cuid})." ($args{cuid}) - default (".ref($singleton->{cuid}).")\n"; 
     618    #ASSERT(not defined($args{cuid}) or ref($args{cuid}) eq '') if DEBUG; 
     619    #die 'here' if (ref($args{cuid}) ne ''); 
     620 
    506621    my $access_type = $args{writeable} ? 'CHANGE' : 'VIEW'; 
    507622 
    508 #see if we are _able_ to test permissions using just an unloaded topic, if not, fall through to load&then test 
    509     throw AccessException( store()->{access}->getReason() ) 
    510       if (  defined( $args{cuid} )  and  
    511             not (store()->{access} 
    512           ->haveAccess( $args{address}, $access_type, $args{cuid}, 
    513               dontload => 1 ) )); 
    514        
    515     if ( defined( $args{from} ) ) { 
    516  
    517         #load will throw exceptions if things go wrong 
    518         $args{from} = load( address => $args{from} ) 
    519           unless ( $args{from}->isa('Foswiki::Address') ); 
     623    my $result; 
     624    $args{address} = $singleton->getResourceAddressOrCachedResource($args{address}); 
     625    die "recursion? - $functionname(".$singleton->{count}{$functionname}{$args{address}->getPath()}.") ".$args{address}->getPath() if ($singleton->{count}{$functionname}{$args{address}->getPath()}++ > 10); 
     626 
     627    print STDERR "-call: $functionname: ".($args{address}->getPath())."\n"; 
     628 
     629 
     630#    if (ref($args{address}) eq 'Foswiki::Meta') { 
     631#        $result = $args{address}; 
     632#    } else  
     633{ 
     634 
     635    #see if we are _able_ to test permissions using just an unloaded topic, if not, fall through to load&then test 
     636        throw AccessException( $singleton->{access}->getReason() ) 
     637          if (  defined( $args{cuid} )  and  
     638                not ($singleton->{access} 
     639              ->haveAccess( $access_type, $args{cuid}, $args{address},  
     640                  dontload => 1 ) )); 
     641           
     642#        if ( defined( $args{from} ) ) { 
     643# 
     644#            #load will throw exceptions if things go wrong 
     645#            $args{from} = load( address => $args{from} ) 
     646#              unless ( $args{from}->isa('Foswiki::Address') ); 
     647#        } 
     648 
     649    #$cfg::Foswiki{Stores} is an ordered list, managed by configure that prioritises the cache stores first. 
     650        foreach my $impl ( @{ $singleton->{stores} } ) { 
     651 
     652    #the impl is also able to throw exceptions - as there might be a store based permissions impl 
     653            if (not defined($impl->{impl})) { 
     654                eval "require ".$impl->{module}; 
     655                ASSERT( !$@, $@ ) if DEBUG; 
     656                $impl->{impl} = $Foswiki::cfg{Store}{Implementation}->new(); 
     657            } 
     658            #$impl->{impl} ||= $impl.'::new'( store => $impl ) || next; 
     659            $result = $impl->{impl}->$functionname(%args); 
     660            last if ( defined($result) ); 
     661        } 
     662        if ( 
     663                    ($functionname eq 'exists') or  
     664                    ($functionname eq 'atomicLockInfo') or  
     665                    ($functionname eq 'atomicLock') 
     666                    ) { 
     667            print STDERR "-$functionname => ".(defined($result)?$result:'undef')."\n"; 
     668            return $result ; 
     669        } 
     670        throw DoesNotExist(%args) 
     671          unless ( defined($result) ); 
     672      } 
     673 
     674    if (ref($result) eq 'Foswiki::Meta') { 
     675        #now to make sure we're allowed to give it to the user. 
     676 
     677        foreach my $impl ( @{ $singleton->{stores} } ) { 
     678            if (not defined($impl->{impl})) { 
     679                eval "require ".$impl->{module}; 
     680                ASSERT( !$@, $@ ) if DEBUG; 
     681                $impl->{impl} = $Foswiki::cfg{Store}{Implementation}->new(); 
     682            } 
     683 
     684    #a listener for load events. 
     685    #TODO: kill this and replace with call to logger, which stores can choose to consume! 
     686            $impl->{impl}->log( %args, return => $result ); 
     687        } 
     688 
     689    #can't do any better with the __current__ ACL impl, but there should be a call before the readData for real store-fastening 
     690        ASSERT(ref($args{cuid}) eq ''); 
     691        #print STDERR "..cUID isa ".ref($args{cuid})." ($args{cuid})\n"; 
     692 
     693        throw AccessException( $singleton->{access}->getReason() ) 
     694          if (  defined( $args{cuid} )  and  
     695                not ($singleton->{access} 
     696              ->haveAccess( $access_type, $args{cuid}, $result ) )); 
    520697    } 
    521698 
    522 #$cfg::Foswiki{Stores} is an ordered list, managed by configure that prioritises the cache stores first. 
    523     my $result; 
    524     foreach my $impl ( @{ $singleton->{stores} } ) { 
    525  
    526 #the impl is also able to throw exceptions - as there might be a store based permissions impl 
    527         if (not defined($impl->{impl})) { 
    528             eval "require ".$impl->{module}; 
    529             ASSERT( !$@, $@ ) if DEBUG; 
    530             $impl->{impl} = $Foswiki::cfg{Store}{Implementation}->new(); 
    531         } 
    532         #$impl->{impl} ||= $impl.'::new'( store => $impl ) || next; 
    533         $result = $impl->{impl}->$functionname(%args); 
    534         last if ( defined($result) ); 
    535     } 
    536     if ( not defined($result) and $args{create} ) { 
    537         $result = create(%args); 
    538     } 
    539     throw DoesNotExist() 
    540       unless ( defined($result) ); 
    541  
    542     foreach my $impl ( @{ $singleton->{stores} } ) { 
    543         if (not defined($impl->{impl})) { 
    544             eval "require ".$impl->{module}; 
    545             ASSERT( !$@, $@ ) if DEBUG; 
    546             $impl->{impl} = $Foswiki::cfg{Store}{Implementation}->new(); 
    547         } 
    548  
    549 #a listener for load events. 
    550 #TODO: kill this and replace with call to logger, which stores can choose to consume! 
    551         $impl->{impl}->log( %args, return => $result ); 
    552     } 
    553  
    554 #can't do any better with the __current__ ACL impl, but there should be a call before the readData for real store-fastening 
    555     throw AccessException( store()->{access}->getReason() ) 
    556       if (  defined( $args{cuid} )  and  
    557             not (store()->{access} 
    558           ->haveAccess( $args{address}, $access_type, $args{cuid} ) )); 
     699           
     700    $singleton->{count}{$functionname}{$args{address}->getPath()}--;           
     701 
    559702    return $result; 
    560703} 
     704 
     705sub cacheResource { 
     706    my $self = shift; 
     707    my %args = @_; 
     708     
     709    #ASSERT(defined($obj->{_text})) if DEBUG; if itsa topic. 
     710    print STDERR "cacheResource(".$args{functionname}.", ".$args{return}->getPath().") \n"; 
     711     
     712    return unless ($args{functionname} eq 'load'); 
     713     
     714    my $name = $args{return}->getPath(); 
     715    $self->{cache}{$name} = $args{return}; 
     716} 
     717 
     718sub getResourceAddressOrCachedResource { 
     719    my $self = shift; 
     720    my $address = shift; 
     721 
     722    $address = Foswiki::Address->new( string=>$address ) 
     723      if (ref($address) eq '');   #justa string/scalar 
     724    $address = Foswiki::Address->new( @$address ) 
     725      if (ref($address) eq 'ARRAY'); 
     726    $address = Foswiki::Address->new( %$address ) 
     727      if (ref($address) eq 'HASH'); 
     728     
     729     
     730    my $name = $address->getPath(); 
     731    return $self->{cache}{$name} if (defined($self->{cache}{$name})); 
     732    return $address; 
     733} 
     734 
     735sub finish { 
     736    undef $singleton->{cache}; 
     737    undef $singleton; 
     738    print STDERR "--------------------------------- end Store singleton\n"; 
     739} 
     740 
    561741 
    5627421; 
  • branches/scratch/core/lib/Foswiki/Store/VC/Handler.pm

    r12542 r12543  
    5757    ASSERT( $store->isa('Foswiki::Store::Interfaces::Store') ) if DEBUG; 
    5858 
    59     if ( UNIVERSAL::isa( $web, 'Foswiki::Meta' ) ) { 
     59    if ( UNIVERSAL::isa( $web, 'Foswiki::Address' ) ) { 
    6060 
    6161        # $web refers to a meta object 
  • branches/scratch/core/lib/Foswiki/Store/VC/Store.pm

    r12542 r12543  
    4343use Foswiki::Meta    (); 
    4444use Foswiki::Sandbox (); 
     45use Foswiki::Serialise(); 
    4546 
    4647BEGIN { 
     
    7374sub getHandler { 
    7475 
    75     #my ( $this, $web, $topic, $attachment ) = @_; 
     76    #my ( $this, $web, $topic, $args{attachment} ) = @_; 
    7677    ASSERT( 0, "Must be implemented by subclasses" ) if DEBUG; 
    7778} 
    7879 
    7980sub readTopic { 
    80     my ( $this, $topicObject, $version ) = @_; 
    81  
    82     my ( $gotRev, $isLatest ) = $this->askListeners($topicObject, $version); 
     81    my ( $this, %args ) = @_; 
     82 
     83    my ( $gotRev, $isLatest ) = $this->askListeners($args{address}, $args{rev}); 
    8384 
    8485    if ( defined($gotRev) and ( $gotRev > 0 or ($isLatest)) ) { 
     
    8788    ASSERT( not $isLatest ) if DEBUG; 
    8889 
    89     my $handler = $this->getHandler($topicObject); 
     90    my $handler = $this->getHandler($args{address}); 
    9091    $isLatest = 0; 
    9192 
    9293    # check that the requested revision actually exists 
    93     if ( defined $version ) { 
    94         if ( !$version || !$handler->revisionExists($version) ) { 
    95             $version = $handler->getLatestRevisionID(); 
     94    if ( defined $args{rev} ) { 
     95        if ( !$args{rev} || !$handler->revisionExists($args{rev}) ) { 
     96            $args{rev} = $handler->getLatestRevisionID(); 
    9697        } 
    9798    } 
    9899 
    99     ( my $text, $isLatest ) = $handler->getRevision($version); 
     100    ( my $text, $isLatest ) = $handler->getRevision($args{rev}); 
    100101    unless ( defined $text ) { 
    101102        ASSERT( not $isLatest ) if DEBUG; 
     
    104105 
    105106    $text =~ s/\r//g;    # Remove carriage returns 
    106     $topicObject->setEmbeddedStoreForm($text); 
     107    $args{address}->setEmbeddedStoreForm($text); 
    107108 
    108109    unless ($handler->noCheckinPending()) { 
    109110        # If a checkin is pending, fix the TOPICINFO 
    110         my $ri = $topicObject->get('TOPICINFO'); 
     111        my $ri = $args{address}->get('TOPICINFO'); 
    111112        my $truth = $handler->getInfo($version); 
    112113        for my $i qw(author version date) { 
     
    132133    # Only check the currently requested topic. 
    133134    if (   $Foswiki::cfg{RCS}{AutoAttachPubFiles} 
    134         && $topicObject->isSessionTopic() ) 
     135        && $args{address}->isSessionTopic() ) 
    135136    { 
    136         my @knownAttachments = $topicObject->find('FILEATTACHMENT'); 
     137        my @knownAttachments = $args{address}->find('FILEATTACHMENT'); 
    137138        my @attachmentsFoundInPub = 
    138139          $handler->synchroniseAttachmentsList( \@knownAttachments ); 
     
    150151                print STDERR 'AutoAttachPubFiles ignoring ' 
    151152                  . $foundAttachment->{name} . ' in ' 
    152                   . $topicObject->getPath() 
     153                  . $args{address}->getPath() 
    153154                  . ' - not a valid Foswiki Attachment filename'; 
    154155            } 
     
    157158                $this->tellListeners( 
    158159                    verb          => 'autoattach', 
    159                     newmeta       => $topicObject, 
     160                    newmeta       => $args{address}, 
    160161                    newattachment => $foundAttachment 
    161162                ); 
     
    163164        } 
    164165 
    165         $topicObject->putAll( 'FILEATTACHMENT', @validAttachmentsFound ) 
     166        $args{address}->putAll( 'FILEATTACHMENT', @validAttachmentsFound ) 
    166167          if @validAttachmentsFound; 
    167168    } 
     
    172173 
    173174sub moveAttachment { 
    174     my ( $this, $oldTopicObject, $oldAttachment, $newTopicObject, 
    175         $newAttachment, $cUID ) 
     175    my ( $this, %args ) 
    176176      = @_; 
    177177 
    178     my $handler = $this->getHandler( $oldTopicObject, $oldAttachment ); 
     178    my $handler = $this->getHandler( $args{from}, $args{fromattachment} ); 
    179179    if ( $handler->storedDataExists() ) { 
    180         $handler->moveAttachment( $this, $newTopicObject->web, 
    181             $newTopicObject->topic, $newAttachment ); 
     180        $handler->moveAttachment( $this, $args{address}->web, 
     181            $args{address}->topic, $args{attachment} ); 
    182182        $this->tellListeners( 
    183183            verb          => 'update', 
    184             oldmeta       => $oldTopicObject, 
    185             oldattachment => $oldAttachment, 
    186             newmeta       => $newTopicObject, 
    187             newattachment => $newAttachment 
     184            oldmeta       => $args{from}, 
     185            oldattachment => $args{fromattachment}, 
     186            newmeta       => $args{address}, 
     187            newattachment => $args{attachment} 
    188188        ); 
    189         $handler->recordChange( $cUID, 0 ); 
     189        $handler->recordChange( $args{cuid}, 0 ); 
    190190    } 
    191191} 
    192192 
    193193sub copyAttachment { 
    194     my ( $this, $oldTopicObject, $oldAttachment, $newTopicObject, 
    195         $newAttachment, $cUID ) 
     194    my ( $this, %args ) 
    196195      = @_; 
    197196 
    198     my $handler = $this->getHandler( $oldTopicObject, $oldAttachment ); 
     197    my $handler = $this->getHandler( $args{from}, $args{fromattachment} ); 
    199198    if ( $handler->storedDataExists() ) { 
    200         $handler->copyAttachment( $this, $newTopicObject->web, 
    201             $newTopicObject->topic, $newAttachment ); 
     199        $handler->copyAttachment( $this, $args{address}->web, 
     200            $args{address}->topic, $args{attachment} ); 
    202201        $this->tellListeners( 
    203202            verb          => 'insert', 
    204             newmeta       => $newTopicObject, 
    205             newattachment => $newAttachment 
     203            newmeta       => $args{address}, 
     204            newattachment => $args{attachment} 
    206205        ); 
    207         $handler->recordChange( $cUID, 0 ); 
     206        $handler->recordChange( $args{cuid}, 0 ); 
    208207    } 
    209208} 
    210209 
    211210sub attachmentExists { 
    212     my ( $this, $topicObject, $att ) = @_; 
    213     my $handler = $this->getHandler( $topicObject, $att ); 
     211    my ( $this, %args ) = @_; 
     212    my $handler = $this->getHandler( $args{address}, $args{attachment} ); 
    214213    return $handler->storedDataExists(); 
    215214} 
    216215 
    217216sub moveTopic { 
    218     my ( $this, $oldTopicObject, $newTopicObject, $cUID ) = @_; 
    219     ASSERT($cUID) if DEBUG; 
    220  
    221     my $handler = $this->getHandler( $oldTopicObject, '' ); 
    222     my $rev = $handler->getLatestRevisionID(); 
    223  
    224     $handler->moveTopic( $this, $newTopicObject->web, $newTopicObject->topic ); 
     217    my ( $this, %args ) = @_; 
     218    ASSERT($args{cuid}) if DEBUG; 
     219 
     220    my $handler = $this->getHandler( $args{from}, '' ); 
     221    $args{rev} = $handler->getLatestRevisionID(); 
     222 
     223    $handler->moveTopic( $this, $args{address}->web, $args{address}->topic ); 
    225224 
    226225    $this->tellListeners( 
    227226        verb    => 'update', 
    228         oldmeta => $oldTopicObject, 
    229         newmeta => $newTopicObject 
     227        oldmeta => $args{from}, 
     228        newmeta => $args{address} 
    230229    ); 
    231230 
    232     if ( $newTopicObject->web ne $oldTopicObject->web ) { 
     231    if ( $args{address}->web ne $args{from}->web ) { 
    233232 
    234233        # Record that it was moved away 
    235         $handler->recordChange( $cUID, $rev ); 
    236     } 
    237  
    238     $handler = $this->getHandler( $newTopicObject, '' ); 
    239     $handler->recordChange( $cUID, $rev ); 
     234        $handler->recordChange( $args{cuid}, $args{rev} ); 
     235    } 
     236 
     237    $handler = $this->getHandler( $args{address}, '' ); 
     238    $handler->recordChange( $args{cuid}, $args{rev} ); 
    240239} 
    241240 
    242241sub moveWeb { 
    243     my ( $this, $oldWebObject, $newWebObject, $cUID ) = @_; 
    244     ASSERT($cUID) if DEBUG; 
    245  
    246     my $handler = $this->getHandler($oldWebObject); 
    247     $handler->moveWeb( $newWebObject->web ); 
     242    my ( $this, %args ) = @_; 
     243    ASSERT($args{cuid}) if DEBUG; 
     244 
     245    my $handler = $this->getHandler($args{from}); 
     246    $handler->moveWeb( $args{address}->web ); 
    248247 
    249248    $this->tellListeners( 
    250249        verb    => 'update', 
    251         oldmeta => $oldWebObject, 
    252         newmeta => $newWebObject 
     250        oldmeta => $args{from}, 
     251        newmeta => $args{address} 
    253252    ); 
    254253 
    255254    # We have to log in the new web, otherwise we would re-create the dir with 
    256255    # a useless .changes. See Item9278 
    257     $handler = $this->getHandler($newWebObject); 
    258     $handler->recordChange( $cUID, 0, 'Moved from ' . $oldWebObject->web ); 
     256    $handler = $this->getHandler($args{address}); 
     257    $handler->recordChange( $args{cuid}, 0, 'Moved from ' . $args{from}->web ); 
    259258} 
    260259 
    261260sub testAttachment { 
    262     my ( $this, $topicObject, $attachment, $test ) = @_; 
    263     my $handler = $this->getHandler( $topicObject, $attachment ); 
    264     return $handler->test($test); 
     261    my ( $this, %args ) = @_; 
     262    my $handler = $this->getHandler( $args{address}, $args{attachment} ); 
     263    return $handler->test($args{test}); 
    265264} 
    266265 
    267266sub openAttachment { 
    268     my ( $this, $topicObject, $att, $mode, @opts ) = @_; 
    269  
    270     my $handler = $this->getHandler( $topicObject, $att ); 
    271     return $handler->openStream( $mode, @opts ); 
     267    my ( $this, %args ) = @_; 
     268 
     269    my $handler = $this->getHandler( $args{address}, $args{attachment} ); 
     270    return $handler->openStream( $args{mode}, %args ); 
    272271} 
    273272 
    274273sub getRevisionHistory { 
    275     my ( $this, $topicObject, $attachment ) = @_; 
    276  
    277     my $itr = $this->askListenersRevisionHistory($topicObject, $attachment); 
     274    my ( $this, %args ) = @_; 
     275     
     276    my $itr = $this->askListenersRevisionHistory($args{address}, $args{attachment}); 
    278277 
    279278    if ( defined($itr) ) { 
     
    281280    } 
    282281 
    283     my $handler = $this->getHandler( $topicObject, $attachment ); 
     282    my $handler = $this->getHandler( $args{address}, $args{attachment} ); 
    284283    return $handler->getRevisionHistory(); 
    285284} 
    286285 
    287286sub getNextRevision { 
    288     my ( $this, $topicObject ) = @_; 
    289     my $handler = $this->getHandler($topicObject); 
     287    my ( $this, %args ) = @_; 
     288    my $handler = $this->getHandler($args{address}); 
    290289    return $handler->getNextRevisionID(); 
    291290} 
    292291 
    293292sub getRevisionDiff { 
    294     my ( $this, $topicObject, $rev2, $contextLines ) = @_; 
    295     ASSERT( defined($contextLines) ) if DEBUG; 
    296  
    297     my $rcs = $this->getHandler($topicObject); 
    298     return $rcs->revisionDiff( $topicObject->getLoadedRev(), $rev2, 
    299         $contextLines ); 
     293    my ( $this, %args ) = @_; 
     294    ASSERT( defined($args{contextLines}) ) if DEBUG; 
     295 
     296    my $rcs = $this->getHandler($args{address}); 
     297    return $rcs->revisionDiff( $args{address}->getLoadedRev(), $args{rev}, 
     298        $args{contextLines} ); 
    300299} 
    301300 
    302301sub getAttachmentVersionInfo { 
    303     my ( $this, $topicObject, $rev, $attachment ) = @_; 
    304     my $handler = $this->getHandler( $topicObject, $attachment ); 
    305     return $handler->getInfo( $rev || 0 ); 
     302    my ( $this, %args ) = @_; 
     303    my $handler = $this->getHandler( $args{address}, $args{attachment} ); 
     304    return $handler->getInfo( $args{rev} || 0 ); 
    306305} 
    307306 
    308307sub getVersionInfo { 
    309     my ( $this, $topicObject ) = @_; 
    310     my $handler = $this->getHandler($topicObject); 
    311     return $handler->getInfo( $topicObject->getLoadedRev() ); 
     308    my ( $this, %args ) = @_; 
     309    my $handler = $this->getHandler($args{address}); 
     310    return $handler->getInfo( $args{address}->getLoadedRev() ); 
    312311} 
    313312 
    314313sub saveAttachment { 
    315     my ( $this, $topicObject, $name, $stream, $cUID, $comment ) = @_; 
    316     my $handler    = $this->getHandler( $topicObject, $name ); 
     314    my ( $this, %args ) = @_; 
     315    my $handler    = $this->getHandler( $args{address}, $args{name} ); 
    317316    my $currentRev = $handler->getLatestRevisionID(); 
    318317    my $nextRev    = $currentRev + 1; 
    319     my $verb = ( $topicObject->hasAttachment($name) ) ? 'update' : 'insert'; 
    320     $handler->addRevisionFromStream( $stream, $comment, $cUID ); 
     318    my $verb = ( $args{address}->hasAttachment($args{name}) ) ? 'update' : 'insert'; 
     319    $handler->addRevisionFromStream( $args{stream}, 'save attachment', $args{cuid} ); 
    321320    $this->tellListeners( 
    322321        verb          => $verb, 
    323         newmeta       => $topicObject, 
    324         newattachment => $name 
     322        newmeta       => $args{address}, 
     323        newattachment => $args{name} 
    325324    ); 
    326     $handler->recordChange( $cUID, $nextRev ); 
     325    $handler->recordChange( $args{cuid}, $nextRev ); 
    327326    return $nextRev; 
    328327} 
    329328 
    330329sub saveTopic { 
    331     my ( $this, $topicObject, $cUID, $options ) = @_; 
    332     ASSERT( $topicObject->isa('Foswiki::Meta') ) if DEBUG; 
    333     ASSERT($cUID) if DEBUG; 
    334  
    335     my $handler = $this->getHandler($topicObject); 
    336  
    337     my $verb = ( $topicObject->existsInStore() ) ? 'update' : 'insert'; 
     330    my ( $this, %args, $options ) = @_; 
     331    ASSERT( $args{address}->isa('Foswiki::Meta') ) if DEBUG; 
     332    ASSERT($args{cuid}) if DEBUG; 
     333 
     334    my $handler = $this->getHandler($args{address}); 
     335 
     336    my $verb = ( $args{address}->existsInStore() ) ? 'update' : 'insert'; 
    338337 
    339338    # just in case they are not sequential 
     
    343342    $ti->{author} = $cUID; 
    344343 
    345     $handler->addRevisionFromText( $topicObject->getEmbeddedStoreForm(), 
    346         'save topic', $cUID, $options->{forcedate} ); 
     344    $handler->addRevisionFromText( $args{address}->getEmbeddedStoreForm(), 
     345        'save topic', $args{cuid}, $options->{forcedate} ); 
    347346 
    348347    my $extra = $options->{minor} ? 'minor' : ''; 
    349     $handler->recordChange( $cUID, $nextRev, $extra ); 
    350  
    351     $this->tellListeners( verb => $verb, newmeta => $topicObject ); 
     348    $handler->recordChange( $args{cuid}, $nextRev, $extra ); 
     349 
     350    $this->tellListeners( verb => $verb, newmeta => $args{address} ); 
    352351 
    353352    return $nextRev; 
     
    355354 
    356355sub repRev { 
    357     my ( $this, $topicObject, $cUID, %options ) = @_; 
    358     ASSERT( $topicObject->isa('Foswiki::Meta') ) if DEBUG; 
    359     ASSERT($cUID) if DEBUG; 
    360     my $info    = $topicObject->getRevisionInfo(); 
    361     my $handler = $this->getHandler($topicObject); 
    362     $handler->replaceRevision( $topicObject->getEmbeddedStoreForm(), 
    363         'reprev', $cUID, $info->{date} ); 
    364     my $rev = $handler->getLatestRevisionID(); 
    365     $handler->recordChange( $cUID, $rev, 'minor, reprev' ); 
    366  
    367     $this->tellListeners( verb => 'update', newmeta => $topicObject ); 
    368  
    369     return $rev; 
     356    my ( $this, %args, %options ) = @_; 
     357    ASSERT( $args{address}->isa('Foswiki::Meta') ) if DEBUG; 
     358    ASSERT($args{cuid}) if DEBUG; 
     359 
     360    my $info    = $args{address}->getRevisionInfo(); 
     361    my $handler = $this->getHandler($args{address}); 
     362    $handler->replaceRevision( $args{address}->getEmbeddedStoreForm(), 
     363        'reprev', $info->{author}, $info->{date} ); 
     364    $args{rev} = $handler->getLatestRevisionID(); 
     365    $handler->recordChange( $args{cuid}, $args{rev}, 'minor, reprev' ); 
     366 
     367    $this->tellListeners( verb => 'update', newmeta => $args{address} ); 
     368 
     369    return $args{rev}; 
    370370} 
    371371 
    372372sub delRev { 
    373     my ( $this, $topicObject, $cUID ) = @_; 
    374     ASSERT( $topicObject->isa('Foswiki::Meta') ) if DEBUG; 
    375     ASSERT($cUID) if DEBUG; 
    376  
    377     my $handler = $this->getHandler($topicObject); 
    378     my $rev     = $handler->getLatestRevisionID(); 
    379     if ( $rev <= 1 ) { 
     373    my ( $this, %args ) = @_; 
     374    ASSERT( $args{address}->isa('Foswiki::Meta') ) if DEBUG; 
     375    ASSERT($args{cuid}) if DEBUG; 
     376 
     377    my $handler = $this->getHandler($args{address}); 
     378    $args{rev}     = $handler->getLatestRevisionID(); 
     379    if ( $args{rev} <= 1 ) { 
    380380        throw Error::Simple( 'Cannot delete initial revision of ' 
    381               . $topicObject->web . '.' 
    382               . $topicObject->topic ); 
     381              . $args{address}->web . '.' 
     382              . $args{address}->topic ); 
    383383    } 
    384384    $handler->deleteRevision(); 
    385385 
    386386    # restore last topic from repository 
    387     $handler->restoreLatestRevision($cUID); 
     387    $handler->restoreLatestRevision($args{cuid}); 
    388388 
    389389    # reload the topic object 
    390     $topicObject->unload(); 
    391     $topicObject->loadVersion(); 
    392  
    393     $this->tellListeners( verb => 'update', newmeta => $topicObject ); 
    394  
    395     $handler->recordChange( $cUID, $rev ); 
    396  
    397     return $rev; 
     390    $args{address}->unload(); 
     391    $args{address}->loadVersion(); 
     392 
     393    $this->tellListeners( verb => 'update', newmeta => $args{address} ); 
     394 
     395    $handler->recordChange( $args{cuid}, $args{rev} ); 
     396 
     397    return $args{rev}; 
    398398} 
    399399 
    400400sub atomicLockInfo { 
    401     my ( $this, $topicObject ) = @_; 
    402     my $handler = $this->getHandler($topicObject); 
     401    my ( $this, %args ) = @_; 
     402    my $handler = $this->getHandler($args{address}); 
    403403    return $handler->isLocked(); 
    404404} 
     
    407407# (doesn't work on all platforms) 
    408408sub atomicLock { 
    409     my ( $this, $topicObject, $cUID ) = @_; 
    410     my $handler = $this->getHandler($topicObject); 
    411     $handler->setLock( 1, $cUID ); 
     409    my ( $this, %args ) = @_; 
     410    my $handler = $this->getHandler($args{address}); 
     411    $handler->setLock( 1, $args{cuid} ); 
    412412} 
    413413 
    414414sub atomicUnlock { 
    415     my ( $this, $topicObject, $cUID ) = @_; 
    416  
    417     my $handler = $this->getHandler($topicObject); 
    418     $handler->setLock( 0, $cUID ); 
     415    my ( $this, %args ) = @_; 
     416 
     417    my $handler = $this->getHandler($args{address}); 
     418    $handler->setLock( 0, $args{cuid} ); 
    419419} 
    420420 
     
    443443sub topicExists { 
    444444    my ( $this, $web, $topic ) = @_; 
    445  
     445     
    446446    return 0 unless defined $web && $web ne ''; 
    447447    $web =~ s#\.#/#go; 
     
    467467 
    468468sub eachAttachment { 
    469     my ( $this, $topicObject ) = @_; 
    470  
    471     my $handler = $this->getHandler($topicObject); 
     469    my ( $this, %args ) = @_; 
     470 
     471    my $handler = $this->getHandler($args{address}); 
    472472    my @list    = $handler->getAttachmentList(); 
    473473    require Foswiki::ListIterator; 
     
    510510 
    511511sub remove { 
    512     my ( $this, $cUID, $topicObject, $attachment ) = @_; 
    513     ASSERT( $topicObject->web ) if DEBUG; 
    514  
    515     my $handler = $this->getHandler( $topicObject, $attachment ); 
     512    my ( $this, %args ) = @_; 
     513    ASSERT( $args{address}->web ) if DEBUG; 
     514 
     515    my $handler = $this->getHandler( $args{address}, $args{attachment} ); 
    516516    $handler->remove(); 
    517517 
    518518    $this->tellListeners( 
    519519        verb          => 'remove', 
    520         oldmeta       => $topicObject, 
    521         oldattachment => $attachment 
     520        oldmeta       => $args{address}, 
     521        oldattachment => $args{attachment} 
    522522    ); 
    523523 
    524524    # Only log when deleting topics or attachment, otherwise we would re-create 
    525525    # an empty directory with just a .changes. See Item9278 
    526     if ( my $topic = $topicObject->topic ) { 
    527         $handler->recordChange( $cUID, 0, 'Deleted ' . $topic ); 
    528     } 
    529     elsif ($attachment) { 
    530         $handler->recordChange( $cUID, 0, 'Deleted attachment ' . $attachment ); 
     526    if ( my $topic = $args{address}->topic ) { 
     527        $handler->recordChange( $args{cuid}, 0, 'Deleted ' . $topic ); 
     528    } 
     529    elsif ($args{attachment}) { 
     530        $handler->recordChange( $args{cuid}, 0, 'Deleted attachment ' . $args{attachment} ); 
    531531    } 
    532532} 
     
    566566 
    567567sub getRevisionAtTime { 
    568     my ( $this, $topicObject, $time ) = @_; 
    569  
    570     my $handler = $this->getHandler($topicObject); 
    571     return $handler->getRevisionAtTime($time); 
     568    my ( $this, %args ) = @_; 
     569 
     570    my $handler = $this->getHandler($args{address}); 
     571    return $handler->getRevisionAtTime($args{time}); 
    572572} 
    573573 
    574574sub getLease { 
    575     my ( $this, $topicObject ) = @_; 
    576  
    577     my $handler = $this->getHandler($topicObject); 
     575    my ( $this, %args ) = @_; 
     576 
     577    my $handler = $this->getHandler($args{address}); 
    578578    my $lease   = $handler->getLease(); 
    579579    return $lease; 
     
    581581 
    582582sub setLease { 
    583     my ( $this, $topicObject, $lease ) = @_; 
    584  
    585     my $handler = $this->getHandler($topicObject); 
    586     $handler->setLease($lease); 
     583    my ( $this, %args ) = @_; 
     584 
     585    my $handler = $this->getHandler($args{address}); 
     586    $handler->setLease($args{lease}); 
    587587} 
    588588 
     
    594594############################################################################ 
    595595# new foswiki 2.0 API methods 
     596 
     597sub save { 
     598    my $this = shift; 
     599    my %args = @_; 
     600    ASSERT($args{address}) if DEBUG; 
     601    my $type = $args{address}->type(); 
     602#    ASSERT($type) if DEBUG; 
     603    if ($type eq 'webpath') { 
     604        return $this->saveWeb($args{address}->web); 
     605    } elsif ($type eq 'topic') { 
     606        return $this->saveTopic(%args); 
     607    }  
     608    die "can't call save(".$args{address}->getPath().")" if DEBUG; 
     609} 
    596610 
    597611sub exists { 
     
    600614    ASSERT($args{address}) if DEBUG; 
    601615    my $type = $args{address}->type(); 
    602     ASSERT($type) if DEBUG; 
    603     if ($type eq 'web') { 
     616#    ASSERT($type) if DEBUG; 
     617    if ($type eq 'webpath') { 
    604618        return $this->webExists($args{address}->web); 
    605619    } elsif ($type eq 'topic') { 
    606620        return $this->topicExists($args{address}->web, $args{address}->topic); 
    607621    }  
    608     die "can't call exists($type)" if DEBUG; 
     622    die "can't call exists(".$args{address}->getPath().") cos its type = $type " if DEBUG; 
     623} 
     624 
     625sub create { 
     626    my $this = shift; 
     627    my %args = @_; 
     628    ASSERT($args{address}) if DEBUG; 
     629    my $type = $args{address}->type(); 
     630    ASSERT($type) if DEBUG; 
     631    if ($type eq 'webpath') { 
     632        my $newResource =  Foswiki::Meta->NEWnew( @_ ); 
     633        return $newResource; 
     634    } elsif ($type eq 'topic') { 
     635        my $newResource =  Foswiki::Meta->NEWnew( @_ ); 
     636        return $newResource; 
     637    }  
     638    die "can't call load($type)" if DEBUG; 
     639} 
     640 
     641sub load { 
     642    my $this = shift; 
     643    my %args = @_; 
     644    ASSERT($args{address}) if DEBUG; 
     645    my $type = $args{address}->type(); 
     646    ASSERT($type) if DEBUG; 
     647    if ($type eq 'webpath') { 
     648        my $newResource =  Foswiki::Meta->NEWnew( @_ ); 
     649        return $newResource; 
     650    } elsif ($type eq 'topic') { 
     651        my $handler = $this->getHandler($args{address}); 
     652 
     653        # check that the requested revision actually exists 
     654        $args{rev} = $args{address}->rev(); 
     655        if ( defined $args{rev} ) { 
     656            if ( !$args{rev} || !$handler->revisionExists($args{rev}) ) { 
     657                $args{rev} = $handler->getLatestRevisionID(); 
     658            } 
     659        } 
     660 
     661        #read the raw text file. 
     662        my ( $text, $isLatest ) = $handler->getRevision($args{rev}); 
     663        unless ( defined $text ) { 
     664            ASSERT( not $isLatest ) if DEBUG; 
     665            return undef; 
     666        } 
     667 
     668        #parse it into a hash so we can use it to create a new Foswiki::Object 
     669        #$text =~ s/\r//g;    # Remove carriage returns 
     670        #$args{address}->setEmbeddedStoreForm($text); 
     671        my $parsedObj = Foswiki::Serialise::deserialise( $Foswiki::Plugins::SESSION, $text, 'embedded' ); 
     672       
     673#        return $this->topicExists($args{address}->web, $args{address}->topic); 
     674        my $newResource =  Foswiki::Meta->NEWnew( data=>$parsedObj, @_ ); 
     675        return $newResource; 
     676    }  
     677    die "can't call load($type)" if DEBUG; 
    609678} 
    610679 
  • branches/scratch/core/lib/Foswiki/UI/Register.pm

    r11121 r12543  
    10071007        $fromWeb = $Foswiki::cfg{SystemWebName}; 
    10081008    } 
    1009     my $tobj = Foswiki::Meta->load( $session, $fromWeb, $template ); 
     1009    my $tobj = Foswiki::Store::load(address=>{web=>$fromWeb, topic=>$template}); 
    10101010 
    10111011    my $log = 
     
    10361036    my $user = $data->{WikiName}; 
    10371037 
    1038     my $topicObject = 
    1039       Foswiki::Meta->new( $session, $Foswiki::cfg{UsersWebName}, $user ); 
     1038    my $topicObject = Foswiki::Store::create(address=>{web=>$Foswiki::cfg{UsersWebName}, topic=>$user}); 
    10401039    my $log; 
    10411040    my $addText; 
Note: See TracChangeset for help on using the changeset viewer.