/** * Recalculates ratings for applications * * @return string */ public function calculateRatingAction() { $applications = $this->fetchApplications(); $count = count($applications); $i = 0; echo "Calculate rating for " . $count . " applications ...\n"; $progress = new ProgressBar($count); foreach ($applications as $application) { $progress->update($i++, 'Application ' . $i . ' / ' . $count); $application->getRating(true); } $progress->update($i, 'Write to database...'); $this->getServiceLocator()->get('repositories')->flush(); $progress->finish(); return PHP_EOL; }
public function setpermissionsAction() { $services = $this->serviceLocator; $repositories = $services->get('repositories'); $repository = $repositories->get('Jobs/Job'); $userRep = $repositories->get('Auth/User'); $jobs = $repository->findAll(); $count = count($jobs); $progress = new CoreProgressBar($count); $i = 0; /* @var Job $job */ foreach ($jobs as $job) { $progress->update($i++, 'Job ' . $i . ' / ' . $count); $permissions = $job->getPermissions(); $user = $job->getUser(); if (!$user instanceof UserInterface) { continue; } try { $group = $user->getGroup($job->getCompany()); } catch (\Exception $e) { continue; } if ($group) { $permissions->grant($group, 'view'); } foreach ($job->getApplications() as $application) { $progress->update($i, 'set app perms...'); $perms = $application->getPermissions(); $perms->inherit($permissions); $jobUser = $userRep->findOneByEmail($job->getContactEmail()); if ($jobUser) { $perms->grant($jobUser, 'change'); } } if (0 == $i % 500) { $progress->update($i, 'write to database...'); $repositories->flush(); } } $progress->update($i, 'write to database...'); $repositories->flush(); $progress->finish(); return PHP_EOL; }
public function resetFilesPermissionsAction() { echo "Loading applications... "; $filter = \Zend\Json\Json::decode($this->params('filter', '{}'), \Zend\Json\Json::TYPE_ARRAY); $filter['$or'] = array(array('attachments' => array('$exists' => 1)), array('contact.image' => array('$exists' => 1))); $applications = $this->fetchApplications($filter); $count = count($applications); echo "[DONE] -> {$count} applications found.\n"; if (!$count) { return; } $progress = new ProgressBar($count); $i = 0; foreach ($applications as $app) { $progress->update($i++, "Process {$i} / {$count}"); $permissions = $app->getPermissions(); $resources = $permissions->getResources(); foreach ($resources as $r) { if ($r instanceof \Auth\Entity\GroupInterface) { $permissions->revoke($r); } } $attachments = $app->getAttachments(); foreach ($attachments as $attachment) { $attachment->getPermissions()->clear()->inherit($permissions); } $contact = $app->getContact(); if ($contact) { $image = $contact->getImage(); if ($image) { $image->getPermissions()->clear()->inherit($permissions); } } } $progress->update($i, '[DONE]'); echo "Flushing..."; $repos = $this->getServiceLocator()->get('repositories'); $repos->flush(); echo " [DONE]\n"; }
/** * removes unfinished applications. Applications, which are in Draft Mode for * more than 24 hours. */ protected function cleanupAction() { $days = 6; $date = new \DateTime(); $date->modify("-{$days} day"); $filter = array("before" => $date->format("Y-m-d"), "isDraft" => 1); $services = $this->getServiceLocator(); $applications = $this->fetchApplications($filter); $documentManager = $services->get('Core/DocumentManager'); $count = count($applications); $i = 0; echo $count . " applications in Draft Mode and older than " . $days . " days will be deleted\n"; $progress = new ProgressBar($count); foreach ($applications as $application) { $progress->update($i++, 'Application ' . $i . ' / ' . $count); $documentManager->remove($application); } $progress->update($i, 'clean up database'); $documentManager->flush(); $progress->finish(); }