From b6da052e080bf656de42077e26411666fa89a003 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 14 May 2009 19:42:37 +0000 Subject: [PATCH] - Added the WebGUI stats system, which will allow site admins to submit information about their site to a central repository on webgui.org which help the developers make WebGUI better. --- docs/changelog/7.x.x.txt | 3 + docs/upgrades/upgrade_7.7.5-7.7.6.pl | 22 ++-- .../Asset/Wobject/EventManagementSystem.pm | 2 +- lib/WebGUI/Operation.pm | 2 + lib/WebGUI/Operation/Statistics.pm | 67 ++++++++++- .../Workflow/Activity/SendWebguiStats.pm | 109 ++++++++++++++++++ .../i18n/English/Activity_SendWebguiStats.pm | 34 ++++++ 7 files changed, 226 insertions(+), 13 deletions(-) create mode 100644 lib/WebGUI/Workflow/Activity/SendWebguiStats.pm create mode 100644 lib/WebGUI/i18n/English/Activity_SendWebguiStats.pm diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 5689491f5..9e63c2c1e 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -9,6 +9,9 @@ - Added support for template attachments; scripts and stylesheets that will be included using style->setScript and setLink instead of just using raw head tags. + - Added the WebGUI stats system, which will allow site admins to submit + information about their site to a central repository on webgui.org which + help the developers make WebGUI better. - fixed #10322: Dataform: wrong attr on script tag - fixed #10336: postReceivedTemplateId not corrected in upgrade_7.6.0-7.6.1 (Jukka Raimovaara / Axxion Oy) - fixed: Crud handling of Form fields with database types that cannot have default values. diff --git a/docs/upgrades/upgrade_7.7.5-7.7.6.pl b/docs/upgrades/upgrade_7.7.5-7.7.6.pl index 15c819981..d399c61d6 100644 --- a/docs/upgrades/upgrade_7.7.5-7.7.6.pl +++ b/docs/upgrades/upgrade_7.7.5-7.7.6.pl @@ -22,6 +22,7 @@ use Getopt::Long; use WebGUI::Session; use WebGUI::Storage; use WebGUI::Asset; +use WebGUI::Workflow; use WebGUI::Utility; my $toVersion = "7.7.6"; @@ -36,6 +37,7 @@ fixDefaultPostReceived($session); addEuVatDbColumns( $session ); addShippingDrivers( $session ); addTransactionTaxColumns( $session ); +sendWebguiStats($session); addDataFormColumns($session); addListingsCacheTimeoutToMatrix( $session ); addSurveyFeedbackTemplateColumn( $session ); @@ -54,13 +56,19 @@ finish($session); #---------------------------------------------------------------------------- -# Describe what our function does -#sub exampleFunction { -# my $session = shift; -# print "\tWe're doing some stuff here that you should know about... " unless $quiet; -# # and here's our code -# print "DONE!\n" unless $quiet; -#} +sub sendWebguiStats { + my $session = shift; + print "\tAdding a workflow to allow users to take part in the WebGUI stats project..." unless $quiet; + my $wf = WebGUI::Workflow->create($session, { + type => 'None', + mode => 'singleton', + title => 'Send WebGUI Stats', + description => 'This workflow sends some information about your site to the central WebGUI statistics repository. No personal information is sent. The information is used to help determine the future direction WebGUI should take.', + }, 'send_webgui_statistics'); + my $act = $wf->addActivity('WebGUI::Workflow::Activity::SendWebguiStats','send_webgui_statistics'); + $act->set('title', 'Send WebGUI Stats'); + print "DONE!\n" unless $quiet; +} #---------------------------------------------------------------------------- sub addListingsCacheTimeoutToMatrix{ diff --git a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm index b8adf7f4a..3e3a05df9 100644 --- a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm +++ b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm @@ -1137,7 +1137,7 @@ className='WebGUI::Asset::Sku::EMSTicket' and state='published' and revisionDate # get a list of tickets already associated with the badge my @existingTickets = $db->buildArray("select ticketAssetId from EMSRegistrantTicket where badgeId=?",[$badgeId]); - + # get assets my $counter = 0; my $totalTickets = scalar(@ids); diff --git a/lib/WebGUI/Operation.pm b/lib/WebGUI/Operation.pm index e83ff19ae..c664436de 100644 --- a/lib/WebGUI/Operation.pm +++ b/lib/WebGUI/Operation.pm @@ -186,6 +186,8 @@ sub getOperations { 'ssoViaSessionId' => 'SSO', + 'disableSendWebguiStats' => 'Statistics', + 'enableSendWebguiStats' => 'Statistics', 'viewStatistics' => 'Statistics', 'makePrintable' => 'Style', diff --git a/lib/WebGUI/Operation/Statistics.pm b/lib/WebGUI/Operation/Statistics.pm index 0274f15fa..881035a36 100644 --- a/lib/WebGUI/Operation/Statistics.pm +++ b/lib/WebGUI/Operation/Statistics.pm @@ -14,7 +14,8 @@ use strict; use WebGUI::AdminConsole; use WebGUI::Cache; use WebGUI::International; -use WebGUI::SQL; +use WebGUI::Workflow::Cron; +use WebGUI::DateTime; =head1 NAME @@ -79,9 +80,54 @@ sub canView { return $user->isInGroup( $session->setting->get("groupIdAdminStatistics") ); } + #------------------------------------------------------------------- -=head2 www_viewStatistics ( $session ) +=head2 www_disableSendWebguiStats () + +Deletes the workflow schedule that sends WebGUI statistics to webgui.org. + +=cut + +sub www_disableSendWebguiStats { + my $session = shift; + my $task = WebGUI::Workflow::Cron->new($session, 'send_webgui_statistics'); + $task->delete; + 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; + # 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'); + return www_viewStatistics($session); +} + + +#------------------------------------------------------------------- + +=head2 www_viewStatistics ( $session, $sent ) Displays information to the user about WebGUI statistics if they are in group Admin (3). @@ -128,8 +174,8 @@ Number of groups. sub www_viewStatistics { my $session = shift; - return $session->privilege->adminOnly() unless canView($session); - my ($output, $data); + return $session->privilege->adminOnly() unless canView($session); + my ($output, $data); my $i18n = WebGUI::International->new($session); my $url = "http://update.webgui.org/latest-version.txt"; my $cache = WebGUI::Cache->new($session,$url,"URL"); @@ -159,7 +205,18 @@ sub www_viewStatistics { ($data) = $session->db->quickArray("select count(*) from groups"); $output .= ''.$i18n->get(89).':'.$data.''; $output .= ''; - return _submenu($session,$output); + + $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); } diff --git a/lib/WebGUI/Workflow/Activity/SendWebguiStats.pm b/lib/WebGUI/Workflow/Activity/SendWebguiStats.pm new file mode 100644 index 000000000..35712ac68 --- /dev/null +++ b/lib/WebGUI/Workflow/Activity/SendWebguiStats.pm @@ -0,0 +1,109 @@ +package WebGUI::Workflow::Activity::SendWebguiStats; + + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2009 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; +use Apache2::ServerUtil; + +=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::defintion() 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 => Apache2::ServerUtil::get_server_version(), + 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 'http://www.webgui.org/stats', [ func => 'receiveStats', stats => $statsAsJson ]; + my $response = $userAgent->request($request); + if ($response->is_error) { + $self->session->errorHandler->error("WebGUI Stats could not be sent."); + } + return $self->COMPLETE; +} + + + +1; + +#vim:ft=perl diff --git a/lib/WebGUI/i18n/English/Activity_SendWebguiStats.pm b/lib/WebGUI/i18n/English/Activity_SendWebguiStats.pm new file mode 100644 index 000000000..1429b8190 --- /dev/null +++ b/lib/WebGUI/i18n/English/Activity_SendWebguiStats.pm @@ -0,0 +1,34 @@ +package WebGUI::i18n::English::Activity_SendWebguiStats; + +use strict; + +our $I18N = { + + 'why to send' => { + message => q|You can choose to send information about your WebGUI site to the central webgui.org stats repository. This helps the developers make WebGUI better by understanding the size of the sites out there, how quickly they grow, and what assets they use most. And you have nothing to worry about because no personally identifiable information is sent.|, + lastUpdated => 0, + context => q|A description of the stats program, what we're sending, and why it's important.| + }, + + 'topicName' => { + message => q|Send WebGUI Statistics|, + lastUpdated => 0, + context => q|The title of the workflow activity.| + }, + + 'enable' => { + message => q|Enable|, + lastUpdated => 0, + context => q|A link label to start the sending of stats.| + }, + + 'disable' => { + message => q|Disable|, + lastUpdated => 0, + context => q|A link label to end the sending of stats.| + }, + +}; + +1; +#vim:ft=perl