Skip to content

Commit

Permalink
Use Access::doAsSuperUser() instead of Piwik::setUserHasSuperUSerAcce…
Browse files Browse the repository at this point in the history
…ss which is deprecated.
  • Loading branch information
diosmosis committed Oct 1, 2014
1 parent 2e17878 commit 5d6355f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 34 deletions.
15 changes: 8 additions & 7 deletions Commands/GenerateAnnotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Piwik\Plugins\VisitorGenerator\Commands;

use Piwik\Access;
use Piwik\Piwik;
use Piwik\Plugin\ConsoleCommand;
use Piwik\Plugins\VisitorGenerator\Generator\Annotations;
Expand All @@ -29,16 +30,16 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
Piwik::setUserHasSuperUserAccess();

$idSite = (int) $input->getOption('idsite');

if (!Site::getSite($idSite)) {
throw new \InvalidArgumentException('idsite is not a valid, no such site found');
}
Access::doAsSuperUser(function () use ($idSite) {
if (!Site::getSite($idSite)) {
throw new \InvalidArgumentException('idsite is not a valid, no such site found');
}

$annotations = new Annotations();
$annotations->generate($idSite);
$annotations = new Annotations();
$annotations->generate($idSite);
});

$this->writeSuccessMessage($output, array('1 Annotation for today generated'));
}
Expand Down
15 changes: 8 additions & 7 deletions Commands/GenerateGoals.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Piwik\Plugins\VisitorGenerator\Commands;

use Piwik\Access;
use Piwik\Piwik;
use Piwik\Plugin\ConsoleCommand;
use Piwik\Plugins\VisitorGenerator\Generator\Goals;
Expand All @@ -29,16 +30,16 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
Piwik::setUserHasSuperUserAccess();

$idSite = (int) $input->getOption('idsite');

if (!Site::getSite($idSite)) {
throw new \InvalidArgumentException('idsite is not a valid, no such site found');
}
$goalIds = Access::doAsSuperUser(function () use ($idSite) {
if (!Site::getSite($idSite)) {
throw new \InvalidArgumentException('idsite is not a valid, no such site found');
}

$goalsGenerator = new Goals();
$goalIds = $goalsGenerator->generate($idSite);
$goalsGenerator = new Goals();
return $goalsGenerator->generate($idSite);
});

$this->writeSuccessMessage($output, array(
sprintf('idsite=%d, %d goals generated (idgoal from %d to %d)', $idSite, count($goalIds), reset($goalIds), end($goalIds))
Expand Down
9 changes: 5 additions & 4 deletions Commands/GenerateUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Piwik\Plugins\VisitorGenerator\Commands;

use Piwik\Access;
use Piwik\Piwik;
use Piwik\Plugin\ConsoleCommand;
use Piwik\Plugins\VisitorGenerator\Generator\Users;
Expand All @@ -28,12 +29,12 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
Piwik::setUserHasSuperUserAccess();

$limit = $input->getOption('limit');

$websiteGenerator = new Users();
$userLogins = $websiteGenerator->generate((int) $limit);
$userLogins = Access::doAsSuperUser(function () use ($limit) {
$websiteGenerator = new Users();
return $websiteGenerator->generate((int) $limit);
});

$this->writeSuccessMessage($output, array(count($userLogins) . ' Users generated'));
}
Expand Down
28 changes: 16 additions & 12 deletions Commands/GenerateVisits.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Piwik\Plugins\VisitorGenerator\Commands;

use Piwik\Access;
use Piwik\Date;
use Piwik\Piwik;
use Piwik\Plugin\ConsoleCommand;
Expand Down Expand Up @@ -36,8 +37,6 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
Piwik::setUserHasSuperUserAccess();

$timer = new Timer();
$days = $this->checkDays($input);
$idSite = $this->checkIdSite($input);
Expand All @@ -52,13 +51,17 @@ protected function execute(InputInterface $input, OutputInterface $output)

if (!$input->getOption('no-fake')) {
$limit = $this->getLimitFakeVisits($input);
$fakeVisits = new VisitsFake();
$nbActionsTotal += $fakeVisits->generate($time, $idSite, $limit);
Access::doAsSuperUser(function () use ($time, $idSite, $limit, &$nbActionsTotal) {
$fakeVisits = new VisitsFake();
$nbActionsTotal += $fakeVisits->generate($time, $idSite, $limit);
});
}

if (!$input->getOption('no-logs')) {
$fromLogs = new VisitsFromLogs();
$nbActionsTotal += $fromLogs->generate($time, $idSite);
Access::doAsSuperUser(function () use ($time, $idSite, &$nbActionsTotal) {
$fromLogs = new VisitsFromLogs();
$nbActionsTotal += $fromLogs->generate($time, $idSite);
});
}

$time += 86400;
Expand Down Expand Up @@ -96,11 +99,12 @@ private function checkIdSite(InputInterface $input)
{
$idSite = (int)$input->getOption('idsite');

if (!Site::getSite($idSite)) {
throw new \InvalidArgumentException('idsite is not a valid, no such site found');
}
return Access::doAsSuperUser(function () use ($idSite) {
if (!Site::getSite($idSite)) {
throw new \InvalidArgumentException('idsite is not a valid, no such site found');
}

return $idSite;
return $idSite;
});
}

}
}
9 changes: 5 additions & 4 deletions Commands/GenerateWebsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Piwik\Plugins\VisitorGenerator\Commands;

use Piwik\Access;
use Piwik\Piwik;
use Piwik\Plugin\ConsoleCommand;
use Piwik\Plugins\VisitorGenerator\Generator\Websites;
Expand All @@ -28,12 +29,12 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
Piwik::setUserHasSuperUserAccess();

$limit = $input->getOption('limit');

$websiteGenerator = new Websites();
$siteIds = $websiteGenerator->generate($limit);
$siteIds = Access::doAsSuperUser(function () use ($limit) {
$websiteGenerator = new Websites();
return $websiteGenerator->generate($limit);
});

$this->writeSuccessMessage($output, array(
sprintf('%d Websites generated (idsite from %d to %d)', count($siteIds), reset($siteIds), end($siteIds))
Expand Down

0 comments on commit 5d6355f

Please sign in to comment.