From d3b574da130cda9df30895f0c1c2ce892b5616a3 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 3 Jan 2012 11:29:00 -0800 Subject: [PATCH] Dump WebGUI Statistics. --- docs/changelog/8.x.x.txt | 1 + etc/WebGUI.conf.original | 7 - lib/WebGUI/Operation/Statistics.pm | 242 ------------------ lib/WebGUI/Wizard/Setup.pm | 53 ---- .../Workflow/Activity/SendWebguiStats.pm | 108 -------- .../7.10.23-8.0.0/removeWebGUIStatistics.pl | 20 ++ 6 files changed, 21 insertions(+), 410 deletions(-) delete mode 100644 lib/WebGUI/Operation/Statistics.pm delete mode 100644 lib/WebGUI/Workflow/Activity/SendWebguiStats.pm create mode 100644 share/upgrades/7.10.23-8.0.0/removeWebGUIStatistics.pl diff --git a/docs/changelog/8.x.x.txt b/docs/changelog/8.x.x.txt index 1016de841..1b9b247a3 100644 --- a/docs/changelog/8.x.x.txt +++ b/docs/changelog/8.x.x.txt @@ -2,4 +2,5 @@ - Replaced the existing caching mechanism with memcached, which results in a 400% improvement to cache speed. See migration.txt for API changes and gotcha.txt for prereq changes. - Added "hot sessions" so sessions interact with the database less. - Added Facebook Auth and FacebookLogin macro. + - Removed the WebGUI statistics program and code. diff --git a/etc/WebGUI.conf.original b/etc/WebGUI.conf.original index 3a59ffe96..a5ce107ca 100644 --- a/etc/WebGUI.conf.original +++ b/etc/WebGUI.conf.original @@ -278,13 +278,6 @@ "url" : "^PageUrl(\"\",func=manageClipboard);", "title" : "^International(948,WebGUI);" }, - "statistics" : { - "icon" : "statistics.gif", - "uiLevel" : 1, - "url" : "^PageUrl(\"\",op=viewStatistics);", - "title" : "^International(437,WebGUI);", - "groupSetting" : "groupIdAdminStatistics" - }, "users" : { "icon" : "users.gif", "uiLevel" : 5, diff --git a/lib/WebGUI/Operation/Statistics.pm b/lib/WebGUI/Operation/Statistics.pm deleted file mode 100644 index 96073da40..000000000 --- a/lib/WebGUI/Operation/Statistics.pm +++ /dev/null @@ -1,242 +0,0 @@ -package WebGUI::Operation::Statistics; - -#------------------------------------------------------------------- -# WebGUI is Copyright 2001-2012 Plain Black Corporation. -#------------------------------------------------------------------- -# Please read the legal notices (docs/legal.txt) and the license -# (docs/license.txt) that came with this distribution before using -# this software. -#------------------------------------------------------------------- -# http://www.plainblack.com info@plainblack.com -#------------------------------------------------------------------- - -use strict; -use WebGUI::AdminConsole; -use WebGUI::International; -use WebGUI::Workflow::Cron; -use WebGUI::DateTime; - -=head1 NAME - -Package WebGUI::Operation::Statistics - -=head1 DESCRIPTION - -Handles displaying statistics about WebGUI. This isn't page count, but rather information -about the number of assets, users, groups, etc. - -#------------------------------------------------------------------- - -=head2 _submenu ( $session, $workarea, $title, $help ) - -Utility routine for creating the AdminConsole for Statistics functions. - -=head3 $session - -The current WebGUI session object. - -=head3 $workarea - -The content to display to the user. - -=head3 $title - -The title of the Admin Console. This should be an entry in the i18n -table in the WebGUI namespace. - -=head3 $help - -An entry in the Help system in the WebGUI namespace. This will be shown -as a link to the user. - -=cut - -sub _submenu { - my $session = shift; - my $workarea = shift; - my $title = shift; - my $i18n = WebGUI::International->new($session); - $title = $i18n->get($title) if ($title); - my $ac = WebGUI::AdminConsole->new($session,"statistics"); - if ($session->setting->get("trackPageStatistics")) { - $ac->addSubmenuItem( $session->url->page('op=viewStatistics'), $i18n->get(144)); - } - return $ac->render($workarea, $title); -} - -#---------------------------------------------------------------------------- - -=head2 canView ( session [, user] ) - -Returns true if the user can administrate this operation. user defaults to -the current user. - -=cut - -sub canView { - my $session = shift; - my $user = shift || $session->user; - return $user->isInGroup( $session->setting->get("groupIdAdminStatistics") ); -} - - -#------------------------------------------------------------------- - -=head2 www_disableSendWebguiStats () - -Deletes the workflow schedule that sends WebGUI statistics to webgui.org. - -=cut - -sub www_disableSendWebguiStats { - my $session = shift; - return $session->privilege->adminOnly() unless canView($session); - my $task = WebGUI::Workflow::Cron->new($session, 'send_webgui_statistics'); - $task->delete; - my $workflow = WebGUI::Workflow->new($session, 'send_webgui_statistics'); - $workflow->set({enabled => 0}); - return www_viewStatistics($session); -} - - -#------------------------------------------------------------------- - -=head2 www_enableSendWebguiStats () - -Creates the workflow schedule that sends WebGUI statistics to webgui.org. - -=cut - -sub www_enableSendWebguiStats { - my $session = shift; - return $session->privilege->adminOnly() unless canView($session); - # we set the current hour, minute, and day of week to send in the stats so we don't DOS webgui.org - # by having everybody sending it at the same time - my $dt = WebGUI::DateTime->new($session, time()); - WebGUI::Workflow::Cron->create($session, { - enabled => 1, - workflowId => 'send_webgui_statistics', - minuteOfHour => $dt->minute, - hourOfDay => $dt->hour, - dayOfWeek => ($dt->dow % 7), - dayOfMonth => '*', - monthOfYear => '*', - priority => 3, - title => 'Send WebGUI Statistics', - }, 'send_webgui_statistics'); - my $workflow = WebGUI::Workflow->new($session, 'send_webgui_statistics'); - $workflow->set({enabled => 1}); - return www_viewStatistics($session); -} - - -#------------------------------------------------------------------- - -=head2 www_viewStatistics ( $session, $sent ) - -Displays information to the user about WebGUI statistics if they are -in group Admin (3). - -=head3 Displayed information - -=over 4 - -=item * - -Newest WebGUI version. - -=item * - -Current WebGUI version, if different from newest. - -=item * - -Number of published assets. - -=item * - -Number of assets set to be packages. - -=item * - -Number of templates - -=item * - -Number of sessions - -=item * - -Number of users. - -=item * - -Number of groups. - -=back - -=cut - -sub www_viewStatistics { - my $session = shift; - return $session->privilege->adminOnly() unless canView($session); - my ($output, $data); - my $i18n = WebGUI::International->new($session); - - # Get the latest WebGUI version - my $url = "http://update.webgui.org/latest-version.txt"; - my $cache = $session->cache; - my $version = $cache->compute( $url, sub { - my $ua = LWP::UserAgent->new( - env_proxy => 1, - agent => "WebGUI/" . $WebGUI::VERSION, - timeout => 30, - ); - - my $r = $ua->get( $url ); - if ( $r->is_error ) { - $session->log->warn( "Could not get latest WebGUI version from '$url': " . $r->status_line ); - } - else { - return $r->decoded_content; - } - } ); - - $output .= ''; - $output .= ''; - if ($version ne $WebGUI::VERSION) { - my @rev = split(/\./,$version); - - $version = ''.$version.''; - } - $output .= ''; - ($data) = $session->db->quickArray("select count(*) from asset where state='published'"); - $output .= ''; - ($data) = $session->db->quickArray("select count(distinct assetId) from assetData where isPackage=1"); - $output .= ''; - ($data) = $session->db->quickArray("select count(distinct(assetId)) from template"); - $output .= ''; - ($data) = $session->db->quickArray("select count(*) from userSession"); - $output .= ''; - ($data) = $session->db->quickArray("select count(*) from users"); - $output .= ''; - ($data) = $session->db->quickArray("select count(*) from groups"); - $output .= ''; - $output .= '
'.$i18n->get(145).':'.$WebGUI::VERSION.'-'.$WebGUI::STATUS.'
'.$i18n->get(349).':'.$version.'
'.$i18n->get(147).':'.$data.'
'.$i18n->get(794).':'.$data.'
'.$i18n->get(792).':'.$data.'
'.$i18n->get(146).':'.$data.'
'.$i18n->get(149).':'.$data.'
'.$i18n->get(89).':'.$data.'
'; - - $output .= q|

|.$i18n->get('why to send','Activity_SendWebguiStats').q|

|; - - my $task = WebGUI::Workflow::Cron->new($session, 'send_webgui_statistics'); - if (defined $task) { - $output .= q|

|.$i18n->get('disable','Activity_SendWebguiStats').q|

|; - } - else { - $output .= q|

|.$i18n->get('enable','Activity_SendWebguiStats').q|

|; - } - $output .= q|

http://www.webgui.org/stats

|; - return _submenu($session,$output); -} - - -1; - diff --git a/lib/WebGUI/Wizard/Setup.pm b/lib/WebGUI/Wizard/Setup.pm index b7625dda5..5a8f965cf 100644 --- a/lib/WebGUI/Wizard/Setup.pm +++ b/lib/WebGUI/Wizard/Setup.pm @@ -22,7 +22,6 @@ sub _get_steps { return [qw( adminAccount companyInformation - siteStats defaultStyle )]; } @@ -296,58 +295,6 @@ sub www_companyInformationSave { #---------------------------------------------------------------------------- -=head2 www_siteStats ( ) - -Opt-in to the global WebGUI statistics - -=cut - -sub www_siteStats { - my ( $self ) = @_; - my $session = $self->session; - my $form = $session->form; - $session->response->setCacheControl("none"); - my $i18n = WebGUI::International->new( $session, "WebGUI" ); - - my $enableForm = $self->getForm; - $enableForm->addField( "hidden", name => "enableStats", value => 1 ); - $enableForm->addField( "submit", name => 'send', value => $i18n->get( 'enable', 'Activity_SendWebguiStats' ) ); - - my $disableForm = $self->getForm; - $disableForm->addField( "hidden", name => "enableStats", value => 0 ); - $disableForm->addField( "submit", name => 'send', value => $i18n->get( 'disable', 'Activity_SendWebguiStats' ) ); - - my $output = '

' . $i18n->get( 'topicName', 'Activity_SendWebguiStats' ) . '

'; - $output .= '

' . $i18n->get( 'why to send', 'Activity_SendWebguiStats' ) . '

-

' . $i18n->get( 'would you participate', 'Activity_SendWebguiStats' ) . '

-
' . $enableForm->toHtml . '
' - . $disableForm->toHtml - . '
' - . '
 
' - ; - - return $output; -} - -#---------------------------------------------------------------------------- - -=head2 www_siteStatsSave ( ) - -Opt-in to the global WebGUI statistics - -=cut - -sub www_siteStatsSave { - my ( $self ) = @_; - my $session = $self->session; - my $form = $session->form; - use WebGUI::Operation::Statistics; - WebGUI::Operation::Statistics::www_enableSendWebguiStats($session) if ( $form->get("enableStats") ); - return; -} - -#---------------------------------------------------------------------------- - =head2 www_defaultStyle ( ) Choose the default site style diff --git a/lib/WebGUI/Workflow/Activity/SendWebguiStats.pm b/lib/WebGUI/Workflow/Activity/SendWebguiStats.pm deleted file mode 100644 index 431129418..000000000 --- a/lib/WebGUI/Workflow/Activity/SendWebguiStats.pm +++ /dev/null @@ -1,108 +0,0 @@ -package WebGUI::Workflow::Activity::SendWebguiStats; - - -=head1 LEGAL - - ------------------------------------------------------------------- - WebGUI is Copyright 2001-2012 Plain Black Corporation. - ------------------------------------------------------------------- - Please read the legal notices (docs/legal.txt) and the license - (docs/license.txt) that came with this distribution before using - this software. - ------------------------------------------------------------------- - http://www.plainblack.com info@plainblack.com - ------------------------------------------------------------------- - -=cut - -use strict; -use base 'WebGUI::Workflow::Activity'; -use HTTP::Request; -use HTTP::Request::Common qw(POST); -use LWP::UserAgent; -use Digest::MD5; - -=head1 NAME - -Package WebGUI::Workflow::Activity::SendWebguiStats - -=head1 DESCRIPTION - -This activity publishes information about your site to webgui.org. No private data is shared. The data is then rolled up on webgui.org/stats - -=head1 SYNOPSIS - -See WebGUI::Workflow::Activity for details on how to use any activity. - -=head1 METHODS - -These methods are available from this class: - -=cut - - -#------------------------------------------------------------------- - -=head2 definition ( session, definition ) - -See WebGUI::Workflow::Activity::definition() for details. - -=cut - -sub definition { - my $class = shift; - my $session = shift; - my $definition = shift; - my $i18n = WebGUI::International->new($session, "Activity_SendWebguiStats"); - push(@{$definition}, { - name=>$i18n->get("topicName"), - properties=> { - } - }); - return $class->SUPER::definition($session,$definition); -} - - -#------------------------------------------------------------------- - -=head2 execute ( [ object ] ) - -See WebGUI::Workflow::Activity::execute() for details. - -=cut - -sub execute { - my $self = shift; - my $object = shift; - my $instance = shift; - my $db = $self->session->db; - my $stats = { - webguiVersion => $WebGUI::VERSION, - perlVersion => sprintf("%vd", $^V), - apacheVersion => 'X', - osType => $^O, - siteId => Digest::MD5::md5_base64($self->session->config->get("sitename")->[0]), # only here to identify the site if the user submits their info a second time - userCount => $db->quickScalar("select count(*) from users"), - groupCount => $db->quickScalar("select count(*) from groups"), - assetCount => $db->quickScalar("select count(*) from asset where state='published'"), - packageCount => $db->quickScalar("select count(distinct assetId) from assetData where isPackage=1"), - assetTypes => $db->buildArrayRefOfHashRefs("select count(*) as quantity,className from asset group by className"), - }; - my $statsAsJson = JSON->new->encode($stats); - my $userAgent = new LWP::UserAgent; - $userAgent->env_proxy; - $userAgent->agent("WebGUI/".$WebGUI::VERSION); - $userAgent->timeout(30); - my $request = POST 'https://www.webgui.org/stats', [ func => 'receiveStats', stats => $statsAsJson ]; - my $response = $userAgent->request($request); - if ($response->is_error) { - $self->session->log->error("WebGUI Stats could not be sent."); - } - return $self->COMPLETE; -} - - - -1; - -#vim:ft=perl diff --git a/share/upgrades/7.10.23-8.0.0/removeWebGUIStatistics.pl b/share/upgrades/7.10.23-8.0.0/removeWebGUIStatistics.pl new file mode 100644 index 000000000..9eed5221d --- /dev/null +++ b/share/upgrades/7.10.23-8.0.0/removeWebGUIStatistics.pl @@ -0,0 +1,20 @@ +use WebGUI::Upgrade::Script; +use File::Spec; +use WebGUI::Paths; +use Cwd qw(realpath); + +start_step "Removing WebGUI statistics workflows and code"; + +config->deleteFromHash( 'adminConsole', 'statistics' ); + +my $workflow = WebGUI::Workflow->new(session, 'send_webgui_statistics'); +$workflow->delete; +##This may not be in there if it is not enabled. +my $task = WebGUI::Workflow::Cron->new(session, 'send_webgui_statistics'); +$task && $task->delete; + +my $webgui_root = realpath( File::Spec->catdir( WebGUI::Paths->configBase, (File::Spec->updir) x 1 ) ); +unlink File::Spec->catfile($webgui_root, 'lib', 'WebGUI', 'Operation', 'Statistics.pm'); +unlink File::Spec->catfile($webgui_root, 'lib', 'WebGUI', 'Workflow', 'Activity', 'SendWebguiStats.pm'); + +done;