--- WebGUI/lib/WebGUI/Storage.pm 2009-07-06 04:41:26.000000000 +0000 +++ /data/WebGUI/lib/WebGUI/Storage.pm 2009-07-20 18:19:26.000000000 +0000 @@ -120,7 +120,7 @@ my $cdnCfg = $self->session->config->get('cdn'); if ( $cdnCfg and $cdnCfg->{'enabled'} ) { if ( $cdnCfg->{'queuePath'} ) { - my $cdnFile = $cdnCfg->{'queuePath'} . '/' . $self->getHexId; + my $cdnFile = $cdnCfg->{'queuePath'} . '/' . $self->getDirectoryId; my $dest; if ( open $dest, '>', $cdnFile ) { close $dest; # created empty file @@ -160,7 +160,7 @@ unlink $cdnFile; } if ( $cdnCfg->{'queuePath'} ) { - $cdnFile = $cdnCfg->{'queuePath'} . '/' . $self->getHexId; + $cdnFile = $cdnCfg->{'queuePath'} . '/' . $self->getDirectoryId; my $dest; if ( open $dest, '>', $cdnFile ) { print $dest "deleted\n"; @@ -690,7 +690,7 @@ and $cdnCfg->{'enabled'} and $cdnCfg->{'syncProgram'} ) { - my $id = $self->getHexId; + my $id = $self->getDirectoryId; my $cmd = sprintf( $cdnCfg->{'deleteProgram'}, $id ); if ( $cmd =~ /$id/ ) { # sanity check, no rm -rf / system($cmd); @@ -698,7 +698,7 @@ $self->_addError("Error running CDN deleteProgram: $?"); } if ( $cdnCfg->{'queuePath'} ) { - unlink $cdnCfg->{'queuePath'} . '/' . $self->getHexId; + unlink $cdnCfg->{'queuePath'} . '/' . $id; } } else { # Presume configuration error, missing %s @@ -827,7 +827,14 @@ my $sub = sub { my $id = shift @ids; return if !$id; - return $class->get( $session, $session->id->fromHex($id) ); + my $storageId; + if (length($id) > 22) { + # convert from hex + $storageId = $session->id->fromHex($id); + } else { + $storageId = $id; + } + return $class->get( $session, $storageId ); }; return $sub; } @@ -1218,12 +1225,12 @@ { if ( $cdnCfg->{'sslUrl'} ) { substr( $cdnCfg->{'sslUrl'}, -1 ) eq '/' and $sep = ''; - $url = $cdnCfg->{'sslUrl'} . $sep . $self->getHexId; + $url = $cdnCfg->{'sslUrl'} . $sep . $self->getDirectoryId; } # else do NOT override $url with CDN URL ($url = $sslUrl || $url) } else { substr( $cdnCfg->{'url'}, -1 ) eq '/' and $sep = ''; - $url = $cdnCfg->{'url'} . $sep . $self->getHexId; + $url = $cdnCfg->{'url'} . $sep . $self->getDirectoryId; } } ## end if ( $cdnCfg and $cdnCfg... if ( defined $file ) { @@ -1631,13 +1638,13 @@ my $originalDir = Cwd::cwd(); my $locDir = join '/', $self->session->config->get('uploadsPath'), @{ $self->{_pathParts} }[ 0 .. 1 ]; chdir $locDir or croak 'Unable to chdir to ' . $locDir . " : $!"; - my $cmd = sprintf( $cdnCfg->{'syncProgram'}, $self->getHexId ); + my $cmd = sprintf( $cdnCfg->{'syncProgram'}, $self->getDirectoryId ); system($cmd); if ($?) { $self->_addError("Error running CDN syncProgram: $?"); } elsif ( $cdnCfg->{'queuePath'} ) { - unlink $cdnCfg->{'queuePath'} . '/' . $self->getHexId; + unlink $cdnCfg->{'queuePath'} . '/' . $self->getDirectoryId; } chdir $originalDir; my $dest; @@ -1719,5 +1726,19 @@ return $temp; } +#------------------------------------------------------------------- + +=head2 getDirectoryId ( ) + +Returns the id in base64 or hex depending on how it's stored in +the uploads path. + +=cut + +sub getDirectoryId { + my $self = shift; + return $self->{_pathParts}[2]; +} + 1; --- WebGUI/sbin/syncToCdn.pl 2009-05-14 00:35:41.000000000 +0000 +++ /data/WebGUI/sbin/syncToCdn.pl 2009-07-20 16:36:53.000000000 +0000 @@ -138,7 +138,7 @@ my $cdnCfg = shift; my $locIter = WebGUI::Storage->getCdnFileIterator($session); while ( my $store = $locIter->() ) { - my $ctrlFile = $cdnCfg->{'queuePath'} . '/' . $session->id->toHex( $store->getId ); + my $ctrlFile = $cdnCfg->{'queuePath'} . '/' . $store->getDirectoryId; if ( -r $ctrlFile and -s $ctrlFile < 12 ) { if ( !-s $ctrlFile ) { # Empty means sync/add/update $store->syncToCdn; @@ -183,7 +183,12 @@ if ( opendir my $S2, "$uDir/$subdir/$sub2" ) { my @fileId = grep { !/^\.+$/ } readdir($S2); foreach my $fileId (@fileId) { - my $store = WebGUI::Storage->get( $session, $session->id->fromHex($fileId) ); + my $storageId = $fileId; + if (length($storageId) > 22) { + # need to convert from hex + $storageId = $session->id->fromHex($storageId); + } + my $store = WebGUI::Storage->get( $session, $storageId ); $store->syncToCdn; # here is the meat } close $S2;