diff --git a/docs/migration.txt b/docs/migration.txt index 863594cfa..2d8260baa 100644 --- a/docs/migration.txt +++ b/docs/migration.txt @@ -7,7 +7,7 @@ developer then this file won't make a lot of sense. CONTENTS -1. Wobject Migration +1. Wobject/Asset Migration 2. Macro Migration 3. Authentication Migration 4. Scheduler Migration @@ -15,8 +15,8 @@ CONTENTS -1. Wobject Migration --------------------- +1. Wobject/Asset Migration +-------------------------- 1.1 Global Unique Wobject IDs @@ -126,6 +126,40 @@ The following tips should also help make your migration easer: been replaced by the WebGUI::Asset::Template asset. +1.3 Quick Read Assets + +As of 6.7.0 Quick Read Assets have been removed. If you adopted quick read +assets between 6.3.0 and 6.7.0 you'll need to change the getLineage rule from +returnQuickReadObjects to returnObjects. + + +1.4 Versioning + +If you're building any custom assets you'll need to write an upgrade script +for 6.6 to 6.7 that will add a revisionDate (bigint) field to your namespace +table. And you'll need to select the revisionDate from the asset table to +initially populate the field in your table. revisionDate along with assetId +should create a composite primary key for your table. Here are some example +SQL queries to get you started in your transition: + + alter table MyAsset add column revisionDate bigint not null; + alter table MyAsset drop primary key; + ...look up the revision date for each asset instance from the asset table... + alter table MyAsset add primary key (assetId,revisionDate); + +Other than that you shouldn't have to make any revisions to your asset to +support versioning. Your collateral tables need not have the revision date as +they'll be tied to the assetId regardless of the revision date. + + +1.5 Constructor API Change + +In 6.7.0 the new() and newByDynamicClass() API's in WebGUI::Asset changed +slightly. In most situations the changes will not cause any problems, but for +some asset developers there may be a slight change. + + + 2. Macro Migration ------------------- diff --git a/docs/upgrades/upgrade_6.6.3-6.7.0.pl b/docs/upgrades/upgrade_6.6.3-6.7.0.pl index 6ac5621dc..ec6b8e3aa 100644 --- a/docs/upgrades/upgrade_6.6.3-6.7.0.pl +++ b/docs/upgrades/upgrade_6.6.3-6.7.0.pl @@ -20,10 +20,10 @@ GetOptions( WebGUI::Session::open("../..",$configFile); +addAssetVersioning(); insertHelpTemplate(); insertXSLTSheets(); insertSyndicatedContentTemplate(); -addAssetVersioning(); WebGUI::Session::close(); @@ -38,6 +38,76 @@ sub addAssetVersioning { commitDate bigint not null default 0, committedBy varchar(22) )"); + my $now = time(); + WebGUI::SQL->write("insert into assetVersionTag values ('pbversion0000000000001','Initial Import','1',$now,'3',$now,'3')"); + WebGUI::SQL->write("insert into assetVersionTag values ('pbversion0000000000002','Auto Commit','1',$now,'3',$now,'3')"); + foreach my $table (qw(FileAsset Post RichEdit Snippet EventsCalendar_Event ImageAsset Thread redirect Shortcut Template Article EventsCalendar IndexedSearch MessageBoard SQLReport Folder Navigation Survey WSClient Collaboration HttpProxy Layout Poll SyndicatedContent Product DataForm wobject)) { + WebGUI::SQL->write("alter table $table add column revisionDate bigint not null"); + WebGUI::SQL->write("update $table set revisionDate=$now"); + WebGUI::SQL->write("alter table $table drop primary key"); + WebGUI::SQL->write("alter table $table add primary key (assetId,revisionDate)"); + } + WebGUI::SQL->write("create table assetData ( + assetId varchar(22) not null, + revisionDate bigint, + revisedBy varchar(22) not null, + tagId varchar(22) not null, + status varchar(35) not null default 'pending', + title varchar(255) not null default 'untitled', + menuTitle varchar(255) not null default 'untitled', + url varchar(255) not null, + ownerUserId varchar(22) not null default '3', + groupIdView varchar(22) not null default '7', + groupIdEdit varchar(22) not null default '4', + startDate bigint not null default 997995720, + endDate bigint not null default 32472169200, + synopsis text, + newWindow int not null default 0, + isHidden int not null default 0, + isPackage int not null default 0, + isPrototype int not null default 0, + encryptPage int not null default 0, + assetSize int not null default 0, + extraHeadTags text, + primary key (assetId,revisionDate) + )"); + my $statement = WebGUI::SQL->prepare("insert into assetData values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); + my $sth = WebGUI::SQL->read("select * from asset"); + while (my $data = $sth->hashRef) { + $statement->execute([ + $data->{assetId}, + $now, + '3', + 'pbversion0000000000001', + 'approved', + $data->{title}, + $data->{menuTitle}, + $data->{url}, + $data->{ownerUserId}, + $data->{groupIdView}, + $data->{groupIdEdit}, + $data->{startDate}, + $data->{endDate}, + $data->{synopsis}, + $data->{newWindow}, + $data->{isHidden}, + $data->{isPackage}, + $data->{isPrototype}, + $data->{encryptPage}, + $data->{assetSize}, + $data->{extraHeadTags} + ]); + } + $sth->finish; + WebGUI::SQL->write("alter table asset add column creationDate bigint not null default 997995720"); + WebGUI::SQL->write("alter table asset add column createdBy varchar(22) not null default '3'"); + WebGUI::SQL->write("alter table asset add column stateChangedBy varchar(22) not null default '3'"); + WebGUI::SQL->write("alter table asset add column isLockedBy varchar(22)"); + WebGUI::SQL->write("update asset set creationDate=$now, createdBy='3'"); + foreach my $field (qw(url groupIdView title menuTitle startDate endDate ownerUserId groupIdEdit synopsis newWindow isHidden isSystem encryptPage assetSize lastUpdated lastUpdatedBy isPackage extraHeadTags isPrototype)) { + WebGUI::SQL->write("alter table asset drop column $field"); + } + } diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index f14339f02..8a76fc4b1 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -52,6 +52,7 @@ A lineage is a concatenated series of sequence numbers, each six digits long, th use WebGUI::Asset; $newAsset = $asset->addChild(\%properties); + $newVersion = $asset->addRevision(\%properties); $boolean = $asset->canEdit("An_Id_AbCdeFGHiJkLMNOP"); $boolean = $asset->canView("An_Id_AbCdeFGHiJkLMNOP"); $asset->cascadeLineage(100001,100101110111); @@ -106,8 +107,10 @@ A lineage is a concatenated series of sequence numbers, each six digits long, th setParent setRank setSize + setVersionLock swapRank trash + unsetVersionLock update updateHistory view @@ -140,13 +143,13 @@ A lineage is a concatenated series of sequence numbers, each six digits long, th www_setParent www_setRank www_view - =head1 METHODS These methods are available from this class: =cut + #------------------------------------------------------------------- =head2 addChild ( properties [, id ] ) @@ -170,24 +173,52 @@ sub addChild { my $lineage = $self->get("lineage").$self->getNextChildRank; $self->{_hasChildren} = 1; WebGUI::SQL->beginTransaction; - WebGUI::SQL->write("insert into asset (assetId, parentId, lineage, state, className, url, startDate, endDate, ownerUserId, groupIdEdit, groupIdView) - values (".quote($id).",".quote($self->getId).", ".quote($lineage).", - 'published', ".quote($properties->{className}).", ".quote($id).", - 997995720, 9223372036854775807,'3','3','7')"); - my $tempAsset = WebGUI::Asset->newByDynamicClass("new",$properties->{className}); - foreach my $definition (@{$tempAsset->definition}) { - unless ($definition->{tableName} eq "asset") { - WebGUI::SQL->write("insert into ".$definition->{tableName}." (assetId) values (".quote($id).")"); - } - } + my $now = time(); + WebGUI::SQL->write("insert into asset (assetId, parentId, lineage, creationDate, createdBy, className, state) values (".quote($id).",".quote($self->getId).", ".quote($lineage).", ".$now.", ".quote($session{user}{userId}).", ".quote($properties->{className}).", 'published')"); + my $temp = WebGUI::Asset->newByPropertyHashRef({ + assetId=>$id, + className=>$properties->{className} + }); + my $newAsset = $temp->addRevision($properties,$now); WebGUI::SQL->commit; - my $newAsset = WebGUI::Asset->newByDynamicClass($id, $properties->{className}); $self->updateHistory("added child ".$id); - $newAsset->updateHistory("created"); - $newAsset->update($properties); return $newAsset; } +#------------------------------------------------------------------- + +=head2 addRevision ( properties [ , revisionDate ] ) + +Adds a revision of an existing asset. Note that programmers should almost never call this method directly, but rather use the update() method instead. + +=head3 properties + +A hash reference containing a list of properties to associate with the child. The only required property value is "className" + +=head3 revisionDate + +An epoch date representing the date/time stamp that this revision was created. Defaults to time(). + +=cut + +sub addRevision { + my $self = shift; + my $properties = shift; + my $now = shift || time(); + my $versionTag = $session{scratch}{versionTag} || 'pbversion0000000000002'; + WebGUI::SQL->write("insert into assetData (assetId, revisionDate, revisedBy, tagId, status, url, startDate, endDate, + ownerUserId, groupIdEdit, groupIdView) values (".quote($self->getId).",".$now.", ".quote($session{user}{userId}).", + ".quote($versionTag).", 'approved', ".quote($self->getId).", 997995720, 9223372036854775807,'3','3','7')"); + foreach my $definition (@{$self->definition}) { + unless ($definition->{tableName} eq "assetData") { + WebGUI::SQL->write("insert into ".$definition->{tableName}." (assetId,revisionDate) values (".quote($self->getId).",".$now.")"); + } + } + my $newVersion = WebGUI::Asset->new($self->getId, $properties->{className}, $now); + $newVersion->updateHistory("created revision"); + $newVersion->update($properties); + return $newVersion; +} #------------------------------------------------------------------- @@ -286,7 +317,7 @@ sub cascadeLineage { my $newLineage = shift; my $oldLineage = shift || $self->get("lineage"); my $now = time(); - my $prepared = WebGUI::SQL->prepare("update asset set lineage=?, lastUpdatedBy=".quote($session{user}{userId}).", lastUpdated=$now where assetId=?"); + my $prepared = WebGUI::SQL->prepare("update asset set lineage=? where assetId=?"); my $descendants = WebGUI::SQL->read("select assetId,lineage from asset where lineage like ".quote($oldLineage.'%')); while (my ($assetId, $lineage) = $descendants->array) { WebGUI::Cache->new("asset_".$assetId)->delete; @@ -337,11 +368,12 @@ Removes asset from lineage, places it in clipboard state. The "gap" in the linea sub cut { my $self = shift; WebGUI::SQL->beginTransaction; - WebGUI::SQL->write("update asset set state='clipboard-limbo', lastUpdatedBy=".quote($session{user}{userId}).", lastUpdated=".time()." where lineage like ".quote($self->get("lineage").'%')." and state='published'"); - WebGUI::SQL->write("update asset set state='clipboard', lastUpdatedBy=".quote($session{user}{userId}).", lastUpdated=".time()." where assetId=".quote($self->getId)); + WebGUI::SQL->write("update asset set state='clipboard-limbo' where lineage like ".quote($self->get("lineage").'%')." and state='published'"); + WebGUI::SQL->write("update asset set state='clipboard', stateChangedBy=".quote($session{user}{userId})." where assetId=".quote($self->getId)); WebGUI::SQL->commit; $self->updateHistory("cut"); $self->{_properties}{state} = "clipboard"; + $self->purgeCache; } #------------------------------------------------------------------- @@ -361,7 +393,7 @@ sub definition { my $definition = shift || []; my @newDef = @{$definition}; push(@newDef, { - tableName=>'asset', + tableName=>'assetData', className=>'WebGUI::Asset', properties=>{ title=>{ @@ -626,7 +658,7 @@ sub fixUrl { if ($session{setting}{urlExtension} ne "" && !($url =~ /\./)) { $url .= ".".$session{setting}{urlExtension}; } - my ($test) = WebGUI::SQL->quickArray("select url from asset where assetId<>".quote($self->getId)." and url=".quote($url)); + my ($test) = WebGUI::SQL->quickArray("select url from assetData where assetId<>".quote($self->getId)." and url=".quote($url)); if ($test) { my @parts = split(/\./,$url); if ($parts[0] =~ /(.*)(\d+$)/) { @@ -757,9 +789,9 @@ sub getAssetAdderLinks { } else { $constraint = quoteAndJoin($session{config}{assets}); } - my $sth = WebGUI::SQL->read("select className,assetId from asset where isPrototype=1 and state='published' and className in ($constraint)"); - while (my ($class,$id) = $sth->array) { - my $asset = WebGUI::Asset->newByDynamicClass($id,$class); + my $sth = WebGUI::SQL->read("select asset.className,asset.assetId,max(assetData.revisionDate) from asset left join assetData on asset.assetId=assetData.assetId where assetData.isPrototype=1 and asset.state='published' and asset.className in ($constraint) group by assetData.assetId"); + while (my ($class,$id,$date) = $sth->array) { + my $asset = WebGUI::Asset->new($id,$class,$date); next unless ($asset->canView && $asset->canAdd && $asset->getUiLevel <= $session{user}{uiLevel}); my $url = $self->getUrl("func=add&class=".$class."&prototype=".$id); $url = WebGUI::URL::append($url,$addToUrl) if ($addToUrl); @@ -807,18 +839,30 @@ sub getAssetsInClipboard { my @assets; my $limit; if ($limitToUser) { - $limit = "and lastUpdatedBy=".quote($userId); + $limit = "and asset.stateChangedBy=".quote($userId); } - my $sth = WebGUI::SQL->read("select assetId, title, className from asset where state='clipboard' $limit order by lastUpdated desc"); - while (my ($id, $title, $class) = $sth->array) { - push(@assets, { - title => $title, - assetId => $id, - className => $class - }); - } - $sth->finish; - return \@assets; + my $sth = WebGUI::SQL->read(" + select + asset.assetId, + max(assetData.revisionDate), + asset.className + from + asset + left join + assetData on asset.assetId=assetData.assetId + where + asset.state='clipboard' + $limit + group by + assetData.assetId + order by + assetData.title desc + "); + while (my ($id, $date, $class) = $sth->array) { + push(@assets, WebGUI::Asset->new($id,$class,$date)); + } + $sth->finish; + return \@assets; } #------------------------------------------------------------------- @@ -844,16 +888,28 @@ sub getAssetsInTrash { my @assets; my $limit; if ($limitToUser) { - $limit = "and lastUpdatedBy=".quote($userId); - } - my $sth = WebGUI::SQL->read("select assetId, title, className from asset where state='trash' $limit order by lastUpdated desc"); - while (my ($id, $title, $class) = $sth->array) { - push(@assets, { - title => $title, - assetId => $id, - className => $class - }); + $limit = "and asset.stateChangedBy=".quote($userId); } + my $sth = WebGUI::SQL->read(" + select + asset.assetId, + max(assetData.revisionDate), + asset.className + from + asset + left join + assetData on asset.assetId=assetData.assetId + where + asset.state='trash' + $limit + group by + assetData.assetId + order by + assetData.title desc + "); + while (my ($id, $date, $class) = $sth->array) { + push(@assets, WebGUI::Asset->new($id,$class,$date)); + } $sth->finish; return \@assets; } @@ -1294,21 +1350,8 @@ sub getLineage { } push(@whereModifiers, "(".join(" or ",@mods).")") if (scalar(@mods)); } - # formulate a where clause - my $where = "state='published'"; - $where = "state in (".quoteAndJoin($rules->{statesToInclude}).")" if (exists $rules->{statesToInclude}); - if (exists $rules->{excludeClasses}) { # deal with exclusions - my @set; - foreach my $className (@{$rules->{excludeClasses}}) { - push(@set,"asset.className not like ".quote($className.'%')); - } - $where .= ' and ('.join(" and ",@set).')'; - } - if (exists $rules->{includeOnlyClasses}) { - $where .= ' and (asset.className in ('.quoteAndJoin($rules->{includeOnlyClasses}).'))'; - } - $where .= " and ".join(" or ",@whereModifiers) if (scalar(@whereModifiers)); - my $tables = "asset "; + # deal with custom joined tables if we must + my $tables = "asset left join assetData on asset.assetId=assetData.assetId "; if (exists $rules->{joinClass}) { my $className = $rules->{joinClass}; my $cmd = "use ".$className; @@ -1317,42 +1360,64 @@ sub getLineage { foreach my $definition (@{$className->definition}) { unless ($definition->{tableName} eq "asset") { my $tableName = $definition->{tableName}; - $tables .= ", $tableName "; - $where .= " and (asset.assetId = $tableName.assetId) "; + $tables .= " left join $tableName on assetData.assetId=".$tableName.".assetId and assetData.revisionDate=".$tableName.".revisionDate"; } last; } } + # formulate a where clause + my $where; + ## custom states + if (exists $rules->{statesToInclude}) { + $where = "asset.state in (".quoteAndJoin($rules->{statesToInclude}).")"; + } else { + $where = "asset.state='published'"; + } + ## get only approved items or those that i'm currently working on + $where .= " and (assetData.status='approved' or assetData.tagId=".quote($session{scratch}{tagId}).")"; + ## class exclusions + if (exists $rules->{excludeClasses}) { + my @set; + foreach my $className (@{$rules->{excludeClasses}}) { + push(@set,"asset.className not like ".quote($className.'%')); + } + $where .= ' and ('.join(" and ",@set).')'; + } + ## class inclusions + if (exists $rules->{includeOnlyClasses}) { + $where .= ' and (asset.className in ('.quoteAndJoin($rules->{includeOnlyClasses}).'))'; + } + ## finish up our where clause + $where .= " and ".join(" or ",@whereModifiers) if (scalar(@whereModifiers)); if (exists $rules->{whereClause}) { $where .= ' and ('.$rules->{whereClause}.')'; } # based upon all available criteria, let's get some assets - my $columns = "asset.assetId, asset.className, asset.parentId"; - my $slavedb; - my $sortOrder = ($rules->{invertTree}) ? "lineage desc" : "lineage asc"; + my $columns = "asset.assetId, asset.className, asset.parentId, max(assetData.revisionDate)"; + my $sortOrder = ($rules->{invertTree}) ? "asset.lineage desc" : "asset.lineage asc"; if (exists $rules->{orderByClause}) { $sortOrder = $rules->{orderByClause}; } - my $sql = "select $columns from $tables where $where order by $sortOrder"; + my $sql = "select $columns from $tables where $where group by assetData.assetId order by $sortOrder"; my @lineage; my %relativeCache; - my $sth = WebGUI::SQL->read($sql, $slavedb); - while (my $properties = $sth->hashRef) { + my $sth = WebGUI::SQL->read($sql); + while (my ($id, $class, $parentId, $version) = $sth->array) { # create whatever type of object was requested my $asset; if ($rules->{returnObjects}) { - if ($self->getId eq $properties->{assetId}) { # possibly save ourselves a hit to the database + if ($self->getId eq $id) { # possibly save ourselves a hit to the database $asset = $self; } else { - $asset = WebGUI::Asset->newByDynamicClass($properties->{assetId}, $properties->{className}); + $asset = WebGUI::Asset->new($id, $class, $version); } } else { - $asset = $properties->{assetId}; + $asset = $id; } # since we have the relatives info now, why not cache it if ($rules->{returnObjects}) { - my $parent = $relativeCache{$properties->{parentId}}; - $relativeCache{$properties->{assetId}} = $asset; + my $parent = $relativeCache{$parentId}; + $relativeCache{$id} = $asset; $asset->{_parent} = $parent; $parent->{_firstChild} = $asset unless(exists $parent->{_firstChild}); $parent->{_lastChild} = $asset; @@ -1481,8 +1546,7 @@ Returns the not found object. The not found object is set in the settings. =cut sub getNotFound { - my $class = shift; - return $class->newByDynamicClass($session{setting}{notFoundPage}); + return WebGUI::Asset->newByDynamicClass($session{setting}{notFoundPage}); } @@ -1497,13 +1561,29 @@ Returns an array of hashes containing title, assetId, and className for all asse sub getPackageList { my $self = shift; my @assets; - my $sth = WebGUI::SQL->read("select assetId, title, className from asset where isPackage=1 order by lastUpdated desc"); - while (my ($id, $title, $class) = $sth->array) { - push(@assets, { - title => $title, - assetId => $id, - className => $class - }); + my $sth = WebGUI::SQL->read(" + select + asset.assetId, + max(assetData.revisionDate), + asset.className + from + asset + left join + assetData on asset.assetId=assetData.assetId + where + assetData.isPackage=1 and + ( + assetData.status='approved' or + assetData.tagId=".quote($session{scratch}{versionTag})." + ) and + asset.state='published' + group by + assetData.assetId + order by + assetData.title desc + "); + while (my ($id, $date, $class) = $sth->array) { + push(@assets, WebGUI::Asset->new($id,$class,$date)); } $sth->finish; return \@assets; @@ -1723,11 +1803,7 @@ sub hasChildren { } elsif (exists $self->{_lastChild}) { $self->{_hasChildren} = 1; } else { - my $hasChildren = WebGUI::Cache->new("childCount_".$self->getId)->get; - unless (defined $hasChildren) { - ($hasChildren) = WebGUI::SQL->quickArray("select count(*) from asset where parentId=".quote($self->getId)); - WebGUI::Cache->new("childCount_".$self->getId)->set($hasChildren); - } + my ($hasChildren) = WebGUI::SQL->quickArray("select count(*) from asset where parentId=".quote($self->getId)); $self->{_hasChildren} = $hasChildren; } } @@ -1736,56 +1812,56 @@ sub hasChildren { #------------------------------------------------------------------- -=head2 new ( assetId||"new" [,overrideProperties] ) +=head2 new ( assetId [, className, revisionDate ] ) Constructor. This does not create an asset. Returns a new object if it can, otherwise returns undef. =head3 assetId -The assetId of the asset you're creating an object reference for. Must not be blank. If specified as "new" then the object properties returns an assetId of new. +The assetId of the asset you're creating an object reference for. Must not be blank. -=head3 overrideProperties +=head3 className -A hash of properties to set besides defaults. +By default we'll use whatever class it is called by like WebGUI::Asset::File->new(), so WebGUI::Asset::File would be used. + +=head3 revisionDate + +An epoch date that represents a specific version of an asset. By default the most recent version will be used. =cut - - sub new { my $class = shift; my $assetId = shift; - my $overrideProperties = shift; - my $properties; - $properties = WebGUI::Cache->new("asset_".$assetId)->get unless($session{var}{adminOn}); - if ($assetId eq "new") { - $properties = $overrideProperties; - $properties->{assetId} = "new"; - $properties->{className} = $class; - } elsif (exists $properties->{assetId}) { + return undef unless ($assetId); + my $className = shift; + my $revisionDate = shift; + unless ($revisionDate) { + ($revisionDate) = WebGUI::SQL->quickArray("select max(revisionDate) from assetData where assetId=".quote($assetId)." group by assetData.assetId order by assetData.revisionDate"); + } + return undef unless ($revisionDate); + if ($className) { + my $cmd = "use ".$className; + eval ($cmd); + if ($@) { + WebGUI::ErrorHandler::error("Couldn't compile asset package: ".$className.". Root cause: ".$@); + return undef; + } + $class = $className; + } + my $properties = WebGUI::Cache->new("asset_".$assetId."/".$revisionDate)->get; + if (exists $properties->{assetId}) { # got properties from cache } else { - my $definitions = $class->definition; - my @definitionsReversed = reverse(@{$definitions}); - shift(@definitionsReversed); my $sql = "select * from asset"; - foreach my $definition (@definitionsReversed) { - $sql .= " left join ".$definition->{tableName}." on asset.assetId=".$definition->{tableName}.".assetId"; + foreach my $definition (@{$class->definition}) { + $sql .= " left join ".$definition->{tableName}." on asset.assetId=".$definition->{tableName}.".assetId and ".$definition->{tableName}.".revisionDate=".$revisionDate; } $sql .= " where asset.assetId=".quote($assetId); $properties = WebGUI::SQL->quickHashRef($sql); return undef unless (exists $properties->{assetId}); - WebGUI::Cache->new("asset_".$assetId)->set($properties,$properties->{cacheTimeout}); + WebGUI::Cache->new("asset_".$assetId."/".$revisionDate)->set($properties,60*60*24); } - if (defined $overrideProperties) { - foreach my $definition (@{$class->definition}) { - foreach my $property (keys %{$definition->{properties}}) { - if (exists $overrideProperties->{$property}) { - $properties->{$property} = $overrideProperties->{$property}; - } - } - } - } if (defined $properties) { my $object = { _properties => $properties }; bless $object, $class; @@ -1796,49 +1872,28 @@ sub new { #------------------------------------------------------------------- -=head2 newByDynamicClass ( assetId [,className,overrideProperties] ) +=head2 newByDynamicClass ( assetId [ , revisionDate ] ) -Returns a new Asset object based upon the className. Returns a "notFoundPage" Asset if className is not specified and can't be looked up. +Similar to new() except that it will look up the classname of an asset rather than making you specify it. Returns undef if it can't find the classname. =head3 assetId Must be a valid assetId -=head3 className +=head3 revisionDate -String of class to use. Defaults to className of assetId, if it can be found in the asset table. - -=head3 overrideProperties - -Any properties to set besides defaults. +A specific revision date for the asset to retrieve. If not specified, the most recent one will be used. =cut sub newByDynamicClass { my $class = shift; my $assetId = shift; + my $revisionDate = shift; return undef unless defined $assetId; - my $className = shift; - my $overrideProperties = shift; - unless (defined $className) { - my $asset = WebGUI::Cache->new("asset_".$assetId)->get; - if (exists $asset->{className}) { - $className = $asset->{className}; - } else { - ($className) = WebGUI::SQL->quickArray("select className from asset where assetId=".quote($assetId)); - } - } - if ($className eq "") { - WebGUI::HTTP::setStatus('404',"Page Not Found"); - WebGUI::ErrorHandler::fatal("The page not found page doesn't exist.") if ($assetId eq $session{setting}{notFoundPage}); - return $class->getNotFound; - } - my $cmd = "use ".$className; - eval ($cmd); - WebGUI::ErrorHandler::fatal("Couldn't compile asset package: ".$className.". Root cause: ".$@) if ($@); - my $assetObject = eval{$className->new($assetId,$overrideProperties)}; - WebGUI::ErrorHandler::fatal("Couldn't create asset instance for ".$assetId.". Root cause: ".$@) if ($@); - return $assetObject; + my ($className) = WebGUI::SQL->quickArray("select className from asset where assetId=".quote($assetId)); + return undef unless ($className); + return WebGUI::Asset->new($assetId,$className,$revisionDate); } @@ -1857,12 +1912,8 @@ Lineage string. sub newByLineage { my $class = shift; my $lineage = shift; - my $asset = WebGUI::Cache->new("lineage_".$lineage)->get; - unless (exists $asset->{assetId}) { - $asset = WebGUI::SQL->quickHashRef("select assetId, className from asset where lineage=".quote($lineage)); - WebGUI::Cache->new("lineage_".$lineage)->set($asset); - } - return WebGUI::Asset->newByDynamicClass($asset->{assetId}, $asset->{className}); + my $asset = WebGUI::SQL->quickHashRef("select assetId, className from asset where lineage=".quote($lineage)); + return WebGUI::Asset->new($asset->{assetId}, $asset->{className}); } #------------------------------------------------------------------- @@ -1911,15 +1962,28 @@ sub newByUrl { $url =~ s/\"//; my $asset; if ($url ne "") { - my $asset = WebGUI::Cache->new("asseturl_".$url)->get; - unless (exists $asset->{assetId}) { - $asset = WebGUI::SQL->quickHashRef("select assetId, className from asset where url=".quote($url)); - WebGUI::Cache->new("asseturl_".$url)->set($asset,3600); - } - if ($asset->{assetId} ne "" || $asset->{className} ne "") { - return WebGUI::Asset->newByDynamicClass($asset->{assetId}, $asset->{className}); + my ($id, $class, $version) = WebGUI::SQL->quickArray(" + select + asset.assetId, + asset.className, + max(assetData.revisionDate) + from + asset + left join + assetData on asset.assetId=assetData.assetId + where + assetData.url=".quote($url)." and + ( + assetData.status='approved' or + assetData.tagId=".quote($session{scratch}{versionTag})." + ) + group by + assetData.assetId + "); + if ($id ne "" || $class ne "") { + return WebGUI::Asset->new($id, $class, $version); } else { - return $class->getNotFound; + return WebGUI::Asset->getNotFound; } } return $class->getDefault; @@ -1942,12 +2006,13 @@ sub paste { my $assetId = shift; my $pastedAsset = WebGUI::Asset->newByDynamicClass($assetId); if ($self->getId eq $pastedAsset->get("parentId") || $pastedAsset->setParent($self)) { - WebGUI::SQL->write("update asset set state='published', lastUpdatedBy=".quote($session{user}{userId}).", lastUpdated=".time()." where lineage like ".quote($self->get("lineage").'%')." and (state='clipboard' or state='clipboard-limbo')"); + WebGUI::SQL->write("update asset set state='published', stateChangedBy=".quote($session{user}{userId})." where lineage like ".quote($self->get("lineage").'%')." and (state='clipboard' or state='clipboard-limbo')"); $self->{_properties}{state} = "published"; $pastedAsset->updateHistory("pasted to parent ".$self->getId); return 1; } return 0; + $self->purgeCache; } #------------------------------------------------------------------- @@ -1978,6 +2043,7 @@ sub processPropertiesFromFormPost { $data{url} =~ s/(.*)\..*/$1/; $data{url} .= '/'.$data{menuTitle}; } + WebGUI::SQL->beginTransaction; $self->update(\%data); foreach my $form (keys %{$session{form}}) { if ($form =~ /^metadata_(.*)$/) { @@ -2000,6 +2066,7 @@ sub processPropertiesFromFormPost { } } } + WebGUI::SQL->commit; } @@ -2072,15 +2139,16 @@ Sets an asset and it's descendants to a state of 'published' regardless of it's sub publish { my $self = shift; - WebGUI::SQL->write("update asset set state='published', lastUpdatedBy=".quote($session{user}{userId}).", lastUpdated=".time()." where lineage like ".quote($self->get("lineage").'%')); + WebGUI::SQL->write("update asset set state='published', stateChangedBy=".quote($session{user}{userId})." where lineage like ".quote($self->get("lineage").'%')); $self->{_properties}{state} = "published"; + $self->purgeCache; } #------------------------------------------------------------------- =head2 purge ( ) -Returns 1. Deletes an asset from tables and removes anything bound to that asset. +Deletes an asset from tables and removes anything bound to that asset. =cut @@ -2093,9 +2161,10 @@ sub purge { WebGUI::SQL->write("delete from ".$definition->{tableName}." where assetId=".quote($self->getId)); } WebGUI::SQL->write("delete from metaData_values where assetId = ".quote($self->getId)); + WebGUI::SQL->write("delete from asset where assetId=".quote($self->getId)); WebGUI::SQL->commit; + $self->purgeCache; $self = undef; - return 1; } #------------------------------------------------------------------- @@ -2108,20 +2177,9 @@ Purges all cache entries associated with this asset. sub purgeCache { my $self = shift; - - my $assetId = $self->getId; - my $assetUrl = $self->getUrl; - $assetUrl =~ s/^\///; #remove beginning / from url - my $lineage = $self->get("lineage"); - - WebGUI::Cache->new("asset_".$assetId)->delete; - WebGUI::Cache->new("asseturl_".$assetUrl)->delete; - WebGUI::Cache->new("childCount_".$assetId)->delete; - WebGUI::Cache->new("firstChild_".$assetId)->delete; - WebGUI::Cache->new("lastChild_".$assetId)->delete; - WebGUI::Cache->new("lineage_".$lineage)->delete; - + WebGUI::Cache->new("asset_".$self->getId."/".$self->get("revisionDate"))->delete; } + #------------------------------------------------------------------- =head2 purgeTree ( ) @@ -2162,11 +2220,12 @@ sub setParent { my $lineage = $newParent->get("lineage").$newParent->getNextChildRank; return 0 if ($lineage =~ m/^$oldLineage/); # can't move it to its own child WebGUI::SQL->beginTransaction; - WebGUI::SQL->write("update asset set parentId=".quote($newParent->getId).", lastUpdatedBy=".quote($session{user}{userId}).", lastUpdated=".time()." where assetId=".quote($self->getId)); + WebGUI::SQL->write("update asset set parentId=".quote($newParent->getId)." where assetId=".quote($self->getId)); $self->cascadeLineage($lineage); WebGUI::SQL->commit; $self->updateHistory("moved to parent ".$newParent->getId); $self->{_properties}{lineage} = $lineage; + $self->purgeCache; return 1; } return 0; @@ -2174,7 +2233,7 @@ sub setParent { #------------------------------------------------------------------- -=head2 setrank ( newRank ) +=head2 setRank ( newRank ) Returns 1. Changes rank of Asset. @@ -2207,6 +2266,7 @@ sub setRank { $self->cascadeLineage($previous,$temp); $self->{_properties}{lineage} = $previous; WebGUI::SQL->commit; + $self->purgeCache; $self->updateHistory("changed rank"); return 1; } @@ -2230,7 +2290,23 @@ sub setSize { foreach my $key (keys %{$self->get}) { $sizetest .= $self->get($key); } - WebGUI::SQL->write("update asset set assetSize=".(length($sizetest)+$extra).", lastUpdatedBy=".quote($session{user}{userId}).", lastUpdated=".time()." where assetId=".quote($self->getId)); + WebGUI::SQL->write("update assetData set assetSize=".(length($sizetest)+$extra)." where assetId=".quote($self->getId)." and revisionDate=".quote($self->get("revisionDate"))); + $self->purgeCache; +} + +#------------------------------------------------------------------- + +=head2 setVersionLock ( ) + +Sets the versioning lock to "on" so that this piece of content may not be edited by anyone else now that it has been edited. + +=cut + +sub setVersionLock { + my $self = shift; + WebGUI::SQL->write("update asset set isLockedBy=".quote($session{user}{userId})." where assetId=".quote($self->getId)); + $self->updateHistory("locked"); + $self->purgeCache; } #------------------------------------------------------------------- @@ -2270,11 +2346,12 @@ Removes asset from lineage, places it in trash state. The "gap" in the lineage i sub trash { my $self = shift; WebGUI::SQL->beginTransaction; - WebGUI::SQL->write("update asset set state='trash-limbo', lastUpdatedBy=".quote($session{user}{userId}).", lastUpdated=".time()." where lineage like ".quote($self->get("lineage").'%')); - WebGUI::SQL->write("update asset set state='trash', lastUpdatedBy=".quote($session{user}{userId}).", lastUpdated=".time()." where assetId=".quote($self->getId)); + WebGUI::SQL->write("update asset set state='trash-limbo' where lineage like ".quote($self->get("lineage").'%')); + WebGUI::SQL->write("update asset set state='trash', stateChangedBy=".quote($session{user}{userId})." where assetId=".quote($self->getId)); WebGUI::SQL->commit; $self->{_properties}{state} = "trash"; $self->updateHistory("trashed"); + $self->purgeCache; } #------------------------------------------------------------------- @@ -2294,11 +2371,27 @@ sub toggleToolbar { } } +#------------------------------------------------------------------- + +=head2 unsetVersionLock ( ) + +Sets the versioning lock to "off" so that this piece of content may be edited once again. + +=cut + +sub unsetVersionLock { + my $self = shift; + WebGUI::SQL->write("update asset set isLockedBy=NULL where assetId=".quote($self->getId)); + $self->updateHistory("unlocked"); + $self->purgeCache; +} + + #------------------------------------------------------------------- =head2 update ( properties ) -Returns 1. Updates properties of an Asset to given or default values. +Updates the properties of an existing revision. If you want to create a new revision, please use addRevision(). =head3 properties @@ -2309,14 +2402,9 @@ Hash reference of properties and values to set. sub update { my $self = shift; my $properties = shift; - $self->purgeCache; - WebGUI::SQL->beginTransaction; + $self->setVersionLock; foreach my $definition (@{$self->definition}) { my @setPairs; - if ($definition->{tableName} eq "asset") { - push(@setPairs,"lastUpdated=".time()); - push(@setPairs,"lastUpdatedBy=".quote($session{user}{userId})); - } foreach my $property (keys %{$definition->{properties}}) { next unless (exists $properties->{$property}); my $value = $properties->{$property}; @@ -2328,12 +2416,11 @@ sub update { push(@setPairs, $property."=".quote($value)); } if (scalar(@setPairs) > 0) { - WebGUI::SQL->write("update ".$definition->{tableName}." set ".join(",",@setPairs)." where assetId=".quote($self->getId)); + WebGUI::SQL->write("update ".$definition->{tableName}." set ".join(",",@setPairs)." where assetId=".quote($self->getId)." and revisionDate=".$self->get("revisionDate")); $self->setSize; } } - WebGUI::SQL->commit; - return 1; + $self->purgeCache; } #------------------------------------------------------------------- @@ -2357,11 +2444,7 @@ sub updateHistory { my $action = shift; my $userId = shift || $session{user}{userId} || '3'; my $dateStamp = time(); - WebGUI::SQL->beginTransaction; - WebGUI::SQL->write("insert into assetHistory (assetId, userId, actionTaken, dateStamp) values ( - ".quote($self->getId).", ".quote($userId).", ".quote($action).", ".$dateStamp.")"); - WebGUI::SQL->write("update asset set lastUpdated=".$dateStamp.", lastUpdatedBy=".quote($userId)." where assetId=".quote($self->getId)); - WebGUI::SQL->commit; + WebGUI::SQL->write("insert into assetHistory (assetId, userId, actionTaken, dateStamp) values (".quote($self->getId).", ".quote($userId).", ".quote($action).", ".$dateStamp.")"); } #------------------------------------------------------------------- @@ -2392,7 +2475,7 @@ sub www_add { my $self = shift; my %prototypeProperties; if ($session{form}{'prototype'}) { - my $prototype = WebGUI::Asset->newByDynamicClass($session{form}{'prototype'},$session{form}{class}); + my $prototype = WebGUI::Asset->new($session{form}{'prototype'},$session{form}{class}); foreach my $definition (@{$prototype->definition}) { # cycle through rather than copying properties to avoid grabbing stuff we shouldn't grab foreach my $property (keys %{$definition->{properties}}) { next if (isIn($property,qw(title menuTitle url isPrototype isPackage))); @@ -2412,10 +2495,12 @@ sub www_add { printableStyleTemplateId => $self->get("printableStyleTemplateId"), isHidden => $self->get("isHidden"), startDate => $self->get("startDate"), - endDate => $self->get("endDate") + endDate => $self->get("endDate"), + className=>$session{form}{class}, + assetId=>"new" ); $properties{isHidden} = 1 unless (WebGUI::Utility::isIn($session{form}{class}, @{$session{config}{assetContainers}})); - my $newAsset = WebGUI::Asset->newByDynamicClass("new",$session{form}{class},\%properties); + my $newAsset = WebGUI::Asset->newByPropertyHashRef(\%properties); $newAsset->{_parent} = $self; return WebGUI::Privilege::insufficient() unless ($newAsset->canAdd); return $newAsset->www_edit(); @@ -2700,6 +2785,8 @@ sub www_edit { Saves and updates history. If canEdit, returns www_manageAssets() if a new Asset is created, otherwise returns www_view(). Will return an insufficient Privilege if canEdit returns False. +NOTE: Don't try to override or overload this method. It won't work. What you are looking for is processPropertiesFromFormPost(). + =cut sub www_editSave { @@ -2710,7 +2797,7 @@ sub www_editSave { $object = $self->addChild({className=>$session{form}{class}}); $object->{_parent} = $self; } else { - $object = $self; + $object = $self->addRevision; } $object->processPropertiesFromFormPost; $object->updateHistory("edited"); @@ -3048,8 +3135,7 @@ sub www_emptyClipboard { my $self = shift; my $ac = WebGUI::AdminConsole->new("clipboard"); return WebGUI::Privilege::insufficient() unless (WebGUI::Grouping::isInGroup(4)); - foreach my $assetData (@{$self->getAssetsInClipboard(!($session{form}{systemClipboard} && WebGUI::Grouping::isInGroup(3)))}) { - my $asset = WebGUI::Asset->newByDynamicClass($assetData->{assetId},$assetData->{className}); + foreach my $asset (@{$self->getAssetsInClipboard(!($session{form}{systemClipboard} && WebGUI::Grouping::isInGroup(3)))}) { $asset->trash; } return $self->www_manageClipboard(); @@ -3067,8 +3153,7 @@ sub www_emptyTrash { my $self = shift; my $ac = WebGUI::AdminConsole->new("trash"); return WebGUI::Privilege::insufficient() unless (WebGUI::Grouping::isInGroup(4)); - foreach my $assetData (@{$self->getAssetsInTrash(!($session{form}{systemTrash} && WebGUI::Grouping::isInGroup(3)))}) { - my $asset = WebGUI::Asset->newByDynamicClass($assetData->{assetId},$assetData->{className}); + foreach my $asset (@{$self->getAssetsInTrash(!($session{form}{systemTrash} && WebGUI::Grouping::isInGroup(3)))}) { $asset->purgeTree; } return $self->www_manageTrash(); @@ -3264,10 +3349,10 @@ sub www_manageAssets { .$child->getRank .",'getUrl("func=manageAssets")."\">".$title ."','getIcon(1)."\" border=\"0\" alt=\"".$child->getName."\" /> ".$child->getName - ."','".WebGUI::DateTime::epochToHuman($child->get("lastUpdated")) + ."','".WebGUI::DateTime::epochToHuman($child->get("revisionDate")) ."','".formatBytes($child->get("assetSize"))."','');\n"; $output .= "assetManager.AddLineSortData('','','','".$title."','".$child->getName - ."','".$child->get("lastUpdated")."','".$child->get("assetSize")."','');\n"; + ."','".$child->get("revisionDate")."','".$child->get("assetSize")."','');\n"; } $output .= ' assetManager.AddButton("'.$i18n->get("delete").'","deleteList","manageAssets"); @@ -3308,9 +3393,8 @@ sub www_manageAssets { my %options; tie %options, 'Tie::IxHash'; my $hasClips = 0; - foreach my $item (@{$self->getAssetsInClipboard(1)}) { - my $asset = WebGUI::Asset->newByDynamicClass($item->{assetId},$item->{className}); - $options{$item->{assetId}} = ''.$asset->getName.' '.$item->{title}; + foreach my $asset (@{$self->getAssetsInClipboard(1)}) { + $options{$asset->getId} = ''.$asset->getName.' '.$asset->getTitle; $hasClips = 1; } if ($hasClips) { @@ -3335,10 +3419,9 @@ sub www_manageAssets { } my $hasPackages = 0; my $packages; - foreach my $item (@{$self->getPackageList}) { - my $asset = WebGUI::Asset->newByDynamicClass($item->{assetId},$item->{className}); + foreach my $asset (@{$self->getPackageList}) { $packages .= ''.$asset->getName.' - {assetId}).'">'.$item->{title}.' ' + getId).'">'.$asset->getTitle.' ' .editIcon("func=edit&proceed=manageAssets",$asset->get("url")) .'
'; $hasPackages = 1; @@ -3368,7 +3451,6 @@ sub www_manageClipboard { my $self = shift; my $ac = WebGUI::AdminConsole->new("clipboard"); return WebGUI::Privilege::insufficient() unless (WebGUI::Grouping::isInGroup(12)); - my @assets; my ($header,$limit); $ac->setHelp("clipboard manage"); if ($session{form}{systemClipboard} && WebGUI::Grouping::isInGroup(3)) { @@ -3382,9 +3464,6 @@ sub www_manageClipboard { 'onclick="return window.confirm(\''.WebGUI::International::get(951).'\')"',"Asset"); $limit = 1; } - foreach my $assetData (@{$self->getAssetsInClipboard($limit)}) { - push(@assets,WebGUI::Asset->newByDynamicClass($assetData->{assetId},$assetData->{className})); - } WebGUI::Style::setLink($session{config}{extrasURL}.'/assetManager/assetManager.css', {rel=>"stylesheet",type=>"text/css"}); WebGUI::Style::setScript($session{config}{extrasURL}.'/assetManager/assetManager.js', {type=>"text/javascript"}); my $i18n = WebGUI::International->new("Asset"); @@ -3397,7 +3476,7 @@ WebGUI::Style::setLink($session{config}{extrasURL}.'/assetManager/assetManager.c assetManager.AddColumn('".$i18n->get("last updated")."','','center',''); assetManager.AddColumn('".$i18n->get("size")."','','right',''); \n"; - foreach my $child (@assets) { + foreach my $child (@{$self->getAssetsInClipboard($limit)}) { my $title = $child->getTitle; $title =~ s/\'/\\\'/g; $output .= "assetManager.AddLine('" @@ -3407,10 +3486,10 @@ WebGUI::Style::setLink($session{config}{extrasURL}.'/assetManager/assetManager.c }) ."','getUrl("func=manageAssets")."\">".$title ."','getIcon(1)."\" border=\"0\" alt=\"".$child->getName."\" /> ".$child->getName - ."','".WebGUI::DateTime::epochToHuman($child->get("lastUpdated")) + ."','".WebGUI::DateTime::epochToHuman($child->get("revisionDate")) ."','".formatBytes($child->get("assetSize"))."');\n"; $output .= "assetManager.AddLineSortData('','".$title."','".$child->getName - ."','".$child->get("lastUpdated")."','".$child->get("assetSize")."');\n"; + ."','".$child->get("revisionDate")."','".$child->get("assetSize")."');\n"; } $output .= 'assetManager.AddButton("'.$i18n->get("delete").'","deleteList","manageClipboard"); assetManager.AddButton("'.$i18n->get("restore").'","restoreList","manageClipboard"); @@ -3488,7 +3567,6 @@ sub www_manageTrash { my $self = shift; my $ac = WebGUI::AdminConsole->new("trash"); return WebGUI::Privilege::insufficient() unless (WebGUI::Grouping::isInGroup(4)); - my @assets; my ($header, $limit); $ac->setHelp("trash manage"); if ($session{form}{systemTrash} && WebGUI::Grouping::isInGroup(3)) { @@ -3498,9 +3576,6 @@ sub www_manageTrash { $ac->addSubmenuItem($self->getUrl('func=manageTrash&systemTrash=1'), WebGUI::International::get(964),"Asset"); $limit = 1; } - foreach my $assetData (@{$self->getAssetsInTrash($limit)}) { - push(@assets,WebGUI::Asset->newByDynamicClass($assetData->{assetId},$assetData->{className})); - } WebGUI::Style::setLink($session{config}{extrasURL}.'/assetManager/assetManager.css', {rel=>"stylesheet",type=>"text/css"}); WebGUI::Style::setScript($session{config}{extrasURL}.'/assetManager/assetManager.js', {type=>"text/javascript"}); my $i18n = WebGUI::International->new("Asset"); @@ -3513,7 +3588,7 @@ sub www_manageTrash { assetManager.AddColumn('".$i18n->get("last updated")."','','center',''); assetManager.AddColumn('".$i18n->get("size")."','','right',''); \n"; - foreach my $child (@assets) { + foreach my $child (@{$self->getAssetsInTrash($limit)}) { my $title = $child->getTitle; $title =~ s/\'/\\\'/g; $output .= "assetManager.AddLine('" @@ -3523,10 +3598,10 @@ sub www_manageTrash { }) ."','getUrl("func=manageAssets")."\">".$title ."','getIcon(1)."\" border=\"0\" alt=\"".$child->getName."\" /> ".$child->getName - ."','".WebGUI::DateTime::epochToHuman($child->get("lastUpdated")) + ."','".WebGUI::DateTime::epochToHuman($child->get("revisionDate")) ."','".formatBytes($child->get("assetSize"))."');\n"; $output .= "assetManager.AddLineSortData('','".$title."','".$child->getName - ."','".$child->get("lastUpdated")."','".$child->get("assetSize")."');\n"; + ."','".$child->get("revisionDate")."','".$child->get("assetSize")."');\n"; } $output .= 'assetManager.AddButton("'.$i18n->get("restore").'","restoreList","manageTrash"); assetManager.Write(); diff --git a/lib/WebGUI/Asset/Shortcut.pm b/lib/WebGUI/Asset/Shortcut.pm index 64f6b2c99..bc1570da2 100644 --- a/lib/WebGUI/Asset/Shortcut.pm +++ b/lib/WebGUI/Asset/Shortcut.pm @@ -115,25 +115,25 @@ sub getEditForm { $tabform->getTab("properties")->yesNo( -name=>"overrideTitle", -value=>$self->getValue("overrideTitle"), - -label=>WebGUI::International::get(7,"Asset_Shortcut") + -label=>WebGUI::International::get(7,"Asset_Shortcut"), -hoverHelp=>WebGUI::International::get('7 description',"Asset_Shortcut") ); $tabform->getTab("display")->yesNo( -name=>"overrideDisplayTitle", -value=>$self->getValue("overrideDisplayTitle"), - -label=>WebGUI::International::get(8,"Asset_Shortcut") + -label=>WebGUI::International::get(8,"Asset_Shortcut"), -hoverHelp=>WebGUI::International::get('8 description',"Asset_Shortcut") ); $tabform->getTab("properties")->yesNo( -name=>"overrideDescription", -value=>$self->getValue("overrideDescription"), - -label=>WebGUI::International::get(9,"Asset_Shortcut") + -label=>WebGUI::International::get(9,"Asset_Shortcut"), -hoverHelp=>WebGUI::International::get('9 description',"Asset_Shortcut") ); $tabform->getTab("display")->yesNo( -name=>"overrideTemplate", -value=>$self->getValue("overrideTemplate"), - -label=>WebGUI::International::get(10,"Asset_Shortcut") + -label=>WebGUI::International::get(10,"Asset_Shortcut"), -hoverHelp=>WebGUI::International::get('10 description',"Asset_Shortcut") ); $tabform->getTab("properties")->readOnly( @@ -150,16 +150,16 @@ sub getEditForm { -extras=>q|Onchange=" if (this.form.shortcutByCriteria[0].checked) { this.form.resolveMultiples.disabled=false; - this.form.proxyCriteria.disabled=false; + this.form.shortcutCriteria.disabled=false; } else { this.form.resolveMultiples.disabled=true; - this.form.proxyCriteria.disabled=true; + this.form.shortcutCriteria.disabled=true; }"| ); $tabform->getTab("properties")->yesNo( -name=>"disableContentLock", -value=>$self->getValue("disableContentLock"), - -label=>WebGUI::International::get("disable content lock","Asset_Shortcut") + -label=>WebGUI::International::get("disable content lock","Asset_Shortcut"), -hoverHelp=>WebGUI::International::get("disable content lock description","Asset_Shortcut") ); if ($self->getValue("shortcutByCriteria") == 0) { @@ -180,7 +180,7 @@ sub getEditForm { $tabform->getTab("properties")->readOnly( -value=>$self->_drawQueryBuilder(), -label=>WebGUI::International::get("Criteria","Asset_Shortcut"), - -hoverHelp=>WebGUI::International::get("Criteria description","Asset_Shortcut"), + -hoverHelp=>WebGUI::International::get("Criteria description","Asset_Shortcut") ); } return $tabform; @@ -232,7 +232,7 @@ A typical hashRef for this function will look like: { proxiedNamespace => "Article", resolveMultiples => "random", - proxyCriteria => "State = Wisconsin AND Country != Sauk" + shortcutCriteria => 'State = "Wisconsin" AND County != "Sauk"' } Most of the time this will be a: @@ -413,8 +413,8 @@ sub _drawQueryBuilder { # Static form fields my $shortcutCriteriaField = WebGUI::Form::textarea({ name=>"shortcutCriteria", - value=>$_[0]->getValue("shortcutCriteria"), - extras=>'style="width: 100%" '.$_[0]->{_disabled} + value=>$self->getValue("shortcutCriteria"), + extras=>'style="width: 100%" '.$self->{_disabled} }); my $conjunctionField = WebGUI::Form::selectList({ name=>"conjunction", diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm index 36c724fa4..4bc78a284 100644 --- a/lib/WebGUI/Asset/Template.pm +++ b/lib/WebGUI/Asset/Template.pm @@ -205,7 +205,7 @@ Specify the namespace to build the list for. sub getList { my $class = shift; my $namespace = shift; - return WebGUI::SQL->buildHashRef("select asset.assetId,asset.title from template left join asset on asset.assetId=template.assetId where template.namespace=".quote($namespace)." and template.showInForms=1 and state='published' order by asset.title",WebGUI::SQL->getSlave); + return WebGUI::SQL->buildHashRef("select assetData.assetId,assetData.title from template left join asset on asset.assetId=template.assetId left join assetData on asset.assetId=assetData.assetId where template.namespace=".quote($namespace)." and template.showInForms=1 and asset.state='published' and (assetData.status='approved' or assetData.tagId=".quote($session{scratch}{versionTag}).") group by assetData.assetId order by assetData.title",WebGUI::SQL->getSlave); } diff --git a/lib/WebGUI/Asset/Wobject/EventsCalendar.pm b/lib/WebGUI/Asset/Wobject/EventsCalendar.pm index f69c3694f..83594ad41 100644 --- a/lib/WebGUI/Asset/Wobject/EventsCalendar.pm +++ b/lib/WebGUI/Asset/Wobject/EventsCalendar.pm @@ -509,10 +509,12 @@ sub www_addStyledEvent { printableStyleTemplateId => $self->get("printableStyleTemplateId"), isHidden => $self->get("isHidden"), startDate => $self->get("startDate"), - endDate => $self->get("endDate") + endDate => $self->get("endDate"), + assetId=> "new", + className=>"WebGUI::Asset::Event" ); $properties{isHidden} = 1 unless (WebGUI::Utility::isIn(ref $session{form}{class}, @{$session{config}{assetContainers}})); - my $newAsset = WebGUI::Asset->newByDynamicClass("new","WebGUI::Asset::Event",\%properties); + my $newAsset = WebGUI::Asset->newByPropertyHashRef(\%properties); $newAsset->{_parent} = $self; #get parent so we can get the parent's style. Hopefully the parent is an EventsCalendar. If not, oh well. # return "You must add an Event as a child of an EventsCalendar." unless ($self->getValue("className") = "WebGUI::Asset::Wobject::EventsCalendar"); diff --git a/lib/WebGUI/Macro/AdminBar.pm b/lib/WebGUI/Macro/AdminBar.pm index 34ad2af59..53116299b 100644 --- a/lib/WebGUI/Macro/AdminBar.pm +++ b/lib/WebGUI/Macro/AdminBar.pm @@ -40,25 +40,23 @@ sub process { $var{'clipboard.label'} = WebGUI::International::get(1082,'Macro_AdminBar'); if (exists $session{asset}) { foreach my $package (@{$session{asset}->getPackageList}) { - my $title = $package->{title}; + my $title = $package->getTitle; $title =~ s/'//g; # stops it from breaking the javascript menus - my $asset = WebGUI::Asset->newByDynamicClass($package->{assetId},$package->{className}); push(@{$var{'package_loop'}},{ - 'url'=>$session{asset}->getUrl("func=deployPackage&assetId=".$package->{assetId}), + 'url'=>$session{asset}->getUrl("func=deployPackage&assetId=".$package->getId), 'label'=>$title, - 'icon.small'=>$asset->getIcon(1), - 'icon'=>$asset->getIcon() + 'icon.small'=>$package->getIcon(1), + 'icon'=>$package->getIcon() }); } $var{contentTypes_loop} = $session{asset}->getAssetAdderLinks; $var{container_loop} = $session{asset}->getAssetAdderLinks(undef,"assetContainers"); - foreach my $item (@{$session{asset}->getAssetsInClipboard(1)}) { - my $title = $item->{title}; + foreach my $asset (@{$session{asset}->getAssetsInClipboard(1)}) { + my $title = $asset->getTitle; $title =~ s/'//g; # stops it from breaking the javascript menus - my $asset = WebGUI::Asset->newByDynamicClass($item->{assetId},$item->{className}); push(@{$var{clipboard_loop}}, { 'label'=>$title, - 'url'=>$session{asset}->getUrl("func=paste&assetId=".$item->{assetId}), + 'url'=>$session{asset}->getUrl("func=paste&assetId=".$asset->getId), 'icon.small'=>$asset->getIcon(1), 'icon'=>$asset->getIcon() }); @@ -67,36 +65,7 @@ sub process { #--admin functions $var{adminConsole_loop} = WebGUI::AdminConsole->getAdminFunction; return WebGUI::Asset::Template->new($templateId)->process(\%var); - %hash = ( - 'http://validator.w3.org/check?uri=referer'=>WebGUI::International::get(399,'Macro_AdminBar'), - ); - my $acParams = WebGUI::AdminConsole->getAdminConsoleParams; - $hash{$acParams->{url}} = $acParams->{title} if ($acParams->{canUse}); -# $acParams = WebGUI::AdminConsole->getAdminFunction("users"); -# $hash{$acParams->{url}} = $acParams->{title} if ($acParams->{canUse}); -# $acParams = WebGUI::AdminConsole->getAdminFunction("groups"); -# $hash{$acParams->{url}} = $acParams->{title} if ($acParams->{canUse}); - $acParams = WebGUI::AdminConsole->getAdminFunction("assets"); - $hash{$acParams->{url}} = $acParams->{title} if ($acParams->{canUse}); - - %hash = sortHash(%hash); - %hash = ( - WebGUI::URL::page('op=switchOffAdmin')=>WebGUI::International::get(12,'Macro_AdminBar'), - %hash - ); - $var{'admin.label'} = WebGUI::International::get(82,'Macro_AdminBar'); - my @admin; - my $i = 0; - foreach my $key (keys %hash) { - push(@admin,{ - 'admin.url'=>$key, - 'admin.label'=>$hash{$key}, - 'admin.count'=>$i - }); - $i++; - } - $var{'admin_loop'} = \@admin; - return WebGUI::Asset::Template->new($templateId)->process(\%var); +# 'http://validator.w3.org/check?uri=referer'=>WebGUI::International::get(399,'Macro_AdminBar'), } diff --git a/lib/WebGUI/Macro/H_homeLink.pm b/lib/WebGUI/Macro/H_homeLink.pm index b59a768ee..ac34c57e0 100644 --- a/lib/WebGUI/Macro/H_homeLink.pm +++ b/lib/WebGUI/Macro/H_homeLink.pm @@ -11,37 +11,31 @@ package WebGUI::Macro::H_homeLink; #------------------------------------------------------------------- use strict; +use WebGUI::Asset; use WebGUI::Asset::Template; use WebGUI::International; use WebGUI::Macro; use WebGUI::Session; -use WebGUI::SQL; #------------------------------------------------------------------- sub process { - my (@param, $temp); - @param = WebGUI::Macro::getParams($_[0]); - if ($session{setting}{defaultPage} eq $session{page}{pageId}) { - $temp = $session{page}{urlizedTitle}; - } else { - ($temp) = WebGUI::SQL->quickArray("select url from asset where assetId=".quote($session{setting}{defaultPage}),WebGUI::SQL->getSlave); - } - $temp = WebGUI::URL::gateway($temp); - if ($param[0] ne "linkonly") { + my ($label, $templateUrl) = WebGUI::Macro::getParams(shift); + my $home = WebGUI::Asset->getDefault; + if ($label ne "linkonly") { my %var; - $var{'homelink.url'} = $temp; - if ($param[0] ne "") { - $var{'homeLink.text'} = $param[0]; + $var{'homelink.url'} = $home->getUrl; + if ($label ne "") { + $var{'homeLink.text'} = $label; } else { $var{'homeLink.text'} = WebGUI::International::get(47,'Macro_H_homeLink'); } - if ($param[1]) { - $temp = WebGUI::Asset::Template->newByUrl($param[1])->process(\%var); + if ($templateUrl) { + return WebGUI::Asset::Template->newByUrl($templateUrl)->process(\%var); } else { - $temp = WebGUI::Asset::Template->new("PBtmpl0000000000000042")->process(\%var); + return WebGUI::Asset::Template->new("PBtmpl0000000000000042")->process(\%var); } } - return $temp; + return $home->getUrl; } diff --git a/lib/WebGUI/i18n/English/Macro_AdminBar.pm b/lib/WebGUI/i18n/English/Macro_AdminBar.pm index 3e7928b68..4c696fb04 100644 --- a/lib/WebGUI/i18n/English/Macro_AdminBar.pm +++ b/lib/WebGUI/i18n/English/Macro_AdminBar.pm @@ -122,10 +122,6 @@ The URL for executing this admin function. lastUpdated => 1031514049 }, - '82' => { - message => q|Administrative functions...|, - lastUpdated => 1031514049 - }, }; 1; diff --git a/www/extras/wobject/Shortcut/querybuilder.js b/www/extras/wobject/Shortcut/querybuilder.js index 27dd1a2d5..92111d715 100644 --- a/www/extras/wobject/Shortcut/querybuilder.js +++ b/www/extras/wobject/Shortcut/querybuilder.js @@ -2,7 +2,7 @@ function addCriteria ( fieldname, opform, valform ) { var form = opform.form; var operator = getValue(opform); var value = getValue(valform); - var criteria = form.proxyCriteria.value; + var criteria = form.shortcutCriteria.value; var conjunction = ""; if(! /^\s*$/.test(criteria)) { conjunction = " " + getValue(form.conjunction) + " "; @@ -15,7 +15,7 @@ function addCriteria ( fieldname, opform, valform ) { value = '"' + value + '"'; } var statement = fieldname + " " + operator + " " + value; - form.proxyCriteria.value = criteria + conjunction + statement; + form.shortcutCriteria.value = criteria + conjunction + statement; } function getValue(sel) {