public function projectInfo($name) { /** @var Database $db */ $db = DB::getMongoDB(); $nodes = $db->nodes->find(['type' => ['$in' => ['project_module', 'project_theme', 'project_core', 'project_distribution', 'project_theme_engine', 'project_drupalorg']], 'field_project_machine_name' => $name])->toArray(); if (count($nodes) == 0) { abort(404); } $node = reset($nodes); return $node; }
public function cijobsRefresh(JobStatusService $job_status_service) { $job = $job_status_service->getJobStatus('pift_ci_jobs', function () { /** @var Database $db */ $db = DB::getMongoDB(); $last_job = $db->pift_ci_jobs->findOne([], ['sort' => ['updated' => -1], 'limit' => 1]); return $last_job->updated; }); if (!empty($job->queued)) { return response()->json(['message' => 'The request is already queued. You should see updates soon.'])->setStatusCode(406); } $req = new PiftCiJobCollectionRequest(['sort' => 'updated', 'direction' => 'DESC']); $options = ['last_updated' => $job->last_updated]; $this->dispatch(new RetrievePiftCiJobCollectionJob($req, $options)); $job->queued = true; $job->save(); return response()->json(['message' => 'We have queued the request. You should see updates soon.'])->setStatusCode(202); }
public function handle(JobStatusService $job_status_service) { $job = $job_status_service->getJobStatus('pift_ci_jobs', function () { /** @var Database $db */ $db = DB::getMongoDB(); $last_job = $db->pift_ci_jobs->findOne([], ['sort' => ['updated' => -1], 'limit' => 1]); return $last_job->updated; }); if (!empty($job->queued)) { $this->error('The request is already queued. You should see updates soon.'); return 1; } $req = new PiftCiJobCollectionRequest(['sort' => 'updated', 'direction' => 'DESC']); $options = ['last_updated' => $job->last_updated]; $this->dispatch(new RetrievePiftCiJobCollectionJob($req, $options)); $job->queued = true; $job->save(); $this->line('The request is now queued. You should see updates soon.'); return 0; }
public function projectIssueCount(Request $request) { /** @var Database $db */ $db = DB::getMongoDB(); $match = ['type' => 'project_issue']; if ($request->input('open_issues')) { $match['field_issue_status'] = ['$in' => array_map(function ($value) { return (string) $value; }, static::$openIssueStatus)]; } $issues = $db->nodes->aggregate([['$match' => $match], ['$group' => ['_id' => ['project' => '$field_project.id'], 'count' => ['$sum' => 1]]], ['$sort' => ['count' => -1]], ['$limit' => 200]])->toArray(); $ret = []; foreach ($issues as $issue) { $project = $db->nodes->findOne(['_id' => $issue->_id->project]); if ($project) { $ret[] = ['_id' => $project['nid'], 'title' => $project['title'], 'machine_name' => $project['field_project_machine_name'], 'type' => $project['type'], 'value' => $issue->count]; } } return response()->json($ret); }
public function projectsGrowth() { /** @var Database $db */ $db = DB::getMongoDB(); $nodes = $db->nodes->aggregate([['$match' => ['type' => ['$in' => ['project_module', 'project_theme', 'project_core', 'project_distribution', 'project_theme_engine']]]], ['$project' => ['_id' => 0, 'created' => 1, 'type' => 1, 'tsday' => ['$mod' => ['$created', 86400]]]], ['$project' => ['_id' => 0, 'type' => 1, 'ts' => ['$subtract' => ['$created', '$tsday']]]], ['$group' => ['_id' => ['day' => '$ts', 'project_type' => '$type'], 'count' => ['$sum' => 1]]], ['$sort' => ['_id.day' => 1]]]); $projects = ['project_module' => [], 'project_theme' => [], 'project_core' => [], 'project_distribution' => [], 'project_theme_engine' => []]; $last_timestamps = ['project_module' => 0, 'project_theme' => 0, 'project_core' => 0, 'project_distribution' => 0, 'project_theme_engine' => 0]; $min_timestamp = mktime(0, 0, 0, 1, 1, 2000); foreach ($nodes as $node) { $type = $node->_id->project_type; // We can just save the last timestamp per each project type as the // list is sorted by timestamp anyway. $last_timestamps[$type] += $node->count; // We don't return data for before 2000. if ($node->_id->day < $min_timestamp) { continue; } $projects[$type][date('Y-m-d', $node->_id->day)] = $last_timestamps[$type]; } return response()->json($projects); }
public function handle(JobStatusService $job_status_service) { $type = $this->argument('type'); $job = $job_status_service->getJobStatus('nodes-' . $type, function () use($type) { /** @var Database $db */ $db = DB::getMongoDB(); $last_job = $db->nodes->findOne([], ['sort' => ['changed' => -1], 'type' => $type, 'limit' => 1]); return $last_job->changed; }); if (!empty($job->queued)) { $this->error('The request is already queued. You should see updates soon.'); return 1; } $req = new NodeCollectionRequest(['type' => $type, 'sort' => 'changed', 'direction' => 'DESC']); $options = ['last_updated' => $job->last_updated, 'type' => $type]; $this->dispatch(new RetrieveNodeCollectionJob($req, $options)); $job->queued = true; $job->save(); $this->line('The request is now queued. You should see updates soon.'); return 0; }
/** * @param string $collectionName * @return bool */ public function deleteCollection($collectionName) { $dbResponse = DB::getMongoDB()->dropCollection($collectionName); return isset($dbResponse['ok']) ? (bool) $dbResponse['ok'] : false; }
public function userCountryGrowth() { /** @var Database $db */ $db = DB::getMongoDB(); $users = $db->users->aggregate([['$project' => ['_id' => 0, 'created' => 1, 'field_country' => 1, 'tsday' => ['$mod' => ['$created', 86400]]]], ['$project' => ['_id' => 0, 'field_country' => 1, 'ts' => ['$subtract' => ['$created', '$tsday']]]], ['$group' => ['_id' => ['day' => '$ts', 'country' => '$field_country'], 'count' => ['$sum' => 1]]], ['$sort' => ['_id.day' => 1]]]); $users_count = []; $last_timestamps = []; $min_timestamp = mktime(0, 0, 0, 1, 1, 2000); foreach ($users as $user) { $country = $user->_id->country; if (!$country) { $country = "na"; } $country = strtolower(str_replace(" ", "-", $country)); if (!isset($last_timestamps[$country])) { $last_timestamps[$country] = 0; } if (!isset($users_count[$country])) { $users_count[$country] = []; } // We can just save the last timestamp per each project type as the // list is sorted by timestamp anyway. $last_timestamps[$country] += $user->count; // We don't return data for before 2000. if ($user->_id->day < $min_timestamp) { continue; } $users_count[$country][date('Y-m-d', $user->_id->day)] = $last_timestamps[$country]; } return response()->json($users_count); }