/** * @param Project $project * * @return Doctrine\Common\Collections\Collection */ public function findLastByRefs(Project $project) { $query = 'SELECT b.* FROM (SELECT * FROM build WHERE build.project_id = ? ORDER BY created_at DESC) b GROUP BY b.ref'; $rsm = new ResultSetMappingBuilder($this->getEntityManager()); $rsm->addRootEntityFromClassMetadata('Model:Build', 'b'); $query = $this->getEntityManager()->createNativeQuery($query, $rsm); $query->setParameter(1, $project->getId()); return $query->execute(); }
public function dump(Project $project, $file = null) { if (null === $file) { $file = tempnam(sys_get_temp_dir(), 'build-ssh-keys-'); } file_put_contents($file, $project->getPrivateKey()); file_put_contents($file . '.pub', $project->getPublicKey()); return $file; }
/** * @todo make a real query */ public function findOneByProjectAndName(Project $project, $ref) { $query = $this->createQueryBuilder('b')->select()->where('b.project = ?1')->andWhere('b.name = ?2')->setParameters([1 => $project->getId(), 2 => $ref])->getQuery(); try { return $query->getSingleResult(); } catch (NoResultException $e) { return null; } }
/** * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function create(Request $request) { if ($request->has('create')) { $project = new Project(); $project->name = $request->get('name'); $project->description = $request->get('description'); $project->save(); } return view('project.create'); }
/** * Schedules a build * * @see App\CoreBundle\EventListener\BuildBranchRelationSubscriber for automatic creation of non-existing branches */ public function schedule(Project $project, $ref, $hash, PayloadInterface $payload = null, $options = []) { $logger = $this->logger; $logger->info('scheduling build', ['project' => $project->getId(), 'ref' => $ref, 'hash' => $hash]); $em = $this->doctrine->getManager(); // @todo I guess this should be in a build.scheduled event listener $alreadyRunningBuilds = $em->getRepository('Model:Build')->findPendingByRef($project, $ref); foreach ($alreadyRunningBuilds as $build) { // @todo instead of retrieving then updating builds to be canceled, directly issue an UPDATE // it should avoid most race conditions if ($build->isScheduled()) { $logger->info('canceling same ref build', ['ref' => $ref, 'canceled_build' => $build->getId()]); $build->setStatus(Build::STATUS_CANCELED); $em->persist($build); $em->flush(); } else { $logger->info('killing same ref build', ['ref' => $ref, 'canceled_build' => $build->getId()]); $scheduler->kill($build); } } $build = new Build(); $build->setProject($project); $build->setStatus(Build::STATUS_SCHEDULED); $build->setRef($ref); $build->setHash($hash); $build->setCommitUrl(sprintf('https://github.com/%s/commit/%s', $project->getFullName(), $hash)); if (null !== $payload) { $build->setIsPullRequest($payload->isPullRequest()); $build->setRawPayload($payload->getRawContent()); } else { $build->setIsPullRequest(false); } if (isset($options['force_local_build_yml']) && $options['force_local_build_yml']) { $build->setForceLocalBuildYml(true); } $builderHost = null; $logger->info('electing builder', ['builder_host_allow' => $this->getOption('builder_host_allow')]); if (count($builderHostAllow = $this->getOption('builder_host_allow')) > 0) { $builderHost = $builderHostAllow[array_rand($builderHostAllow)]; } $build->setBuilderHost($builderHost); /** * @todo move this outside, it belongs in a controller * this will allow to remove the $options argument */ $em->persist($build); $em->flush(); $this->logger->info('sending build order', ['build' => $build->getId(), 'builder_host' => $builderHost]); $this->buildProducer->publish(json_encode(['build_id' => $build->getId()]), $build->getRoutingKey()); $message = $this->messageFactory->createBuildScheduled($build); $this->websocketProducer->publish($message); return $build; }
public function processDelete(Form $form) { $values = $form->getValues(); $this->project->delete($values->id); $this->flashMessage($this->translator->translate('project.deleted'), 'info'); $this->redirect('default'); }
/** * Returns the id of a project given by name. * Throws an exception if no project was found. * * @param string $name The name of the project * @return mixed * @throws RuntimeException */ protected function getProjectIdByName($name) { $collection = Project::where('name', $name)->get(); if ($collection->count() === 0) { throw new RuntimeException('No project found for name: ' . $name); } return $collection->shift()->id; }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); Project::truncate(); Ticket::truncate(); $this->call(ProjectTableSeeder::class); $this->call(TicketTableSeeder::class); Model::reguard(); }
public function index() { $article_num = Article::count(); $user_num = User::count(); $person_num = Person::count(); $project_num = Project::count(); $users = User::sortByDesc('id')->take(5)->get(); return Theme::view('admin.dash.index', compact('article_num', 'user_num', 'person_num', 'project_num', 'users')); }
public function actionDelete($id) { $this['deleteForm']->setDefaults(['id' => $id]); $survey = $this->survey->get($id); if (!$survey) { $this->flashMessage($this->translator->translate('survey.not_found'), 'warning'); $this->redirect('default'); } $this->template->survey = $survey; $this->template->project = $this->project->get($survey->project); }
public function showHome() { //gets latest post $news = Post::where('is_published', 1)->where('is_active', 1)->where('post_type', 1)->orderBy('updated_at', 'desc')->first(); $job = Post::where('is_published', 1)->where('is_active', 1)->where('post_type', 2)->orderBy('updated_at', 'desc')->first(); $product = Product::where('is_active', 1)->orderby('updated_at', 'desc')->first(); $project = Project::where('is_public', 1)->where('is_active', 1)->orderBy('updated_at', 'desc')->first(); $newsContent = htmlspecialchars_decode($news->content, ENT_NOQUOTES); $news->content = $newsContent; //dd($news); return view('pages.home', ['news' => $news, 'job' => $job, 'product' => $product, 'project' => $project]); }
public function show($id = 0) { if (!preg_match("/^[1-9]\\d*\$/", $id)) { return Redirect::to('/'); } $project = Project::find($id); if (empty($project)) { return Redirect::to('/'); } $type = Category::find($project->category_id); if (empty($type)) { return Redirect::to('/'); } ++$project->views; $project->save(); $keywords = $project->keywords; $description = $project->description; if ($project->url != '') { return Redirect::to($project->url); } return Theme::view('project.show', compact('project', 'type', 'keywords', 'description')); }
/** * @param array $ticketIds * @param $projectId * @return array */ private function buildTicketNames($ticketIds, $projectId) { $project = Project::find($projectId); $projectName = $project->name; $result = array(); foreach ($ticketIds as $ticketId) { $result[] = $projectName . '-' . $ticketId; $this->saveNewTicket($ticketId, $project->id); } return $result; }
/** * @param Project $project * * @return Client */ public function configureClientForProject(Project $project) { if (count($project->getUsers()) === 0) { throw new InvalidArgumentException('Project "' . $project->getFullName() . '" has no users'); } return $this->configureClientForUser($project->getUsers()->first()); }
/** * @param array $ticketIds * @param $projectId * @return array */ private function buildTicketNames($ticketIds, $projectId) { $result = []; $project = Project::find($projectId); $ticket = new Ticket(); foreach ($ticketIds as $ticketId) { $ticket->id = $ticketId; $ticket->project = $project; $result[] = $ticket->getTicketName(); } return $result; }
/** * プロジェクトの存在チェック */ private function checkProject($projectId) { $project = Project::find($projectId); if (count($project) > 0) { return $project; } else { return false; } }
public function deleteZone($id) { $projectZoneList = ProjectZoneModel::find($id); $projectID = $projectZoneList->projectId; $project = ProjectModel::find($projectID); $peopleID = $project->peopleId; try { ProjectZoneModel::find($id)->delete(); $alert['msg'] = 'This project zone has been deleted successfully'; $alert['list'] = 'zone'; $alert['type'] = 'success'; } catch (\Exception $ex) { $alert['msg'] = 'This project zone has been already used'; $alert['list'] = 'zone'; $alert['type'] = 'danger'; } return Redirect::route('admin.contact.project', array($peopleID, $projectID))->with('alert', $alert); }
/** * @todo @project_access refactor * * @param Project $project * @param ProjectAccess $access * * @return boolean */ protected function grantProjectAccess(Project $project, ProjectAccess $access) { $args = ['auth:' . $project->getSlug()]; if ($this->feature_ip_access_list || $access->getIp() === '0.0.0.0') { $args[] = $access->getIp(); } if ($this->feature_token_access_list) { $args[] = $access->getToken(); } $args = array_filter($args, function ($arg) { return strlen($arg) > 0; }); return (bool) call_user_func_array([$this->redis, 'sadd'], $args); }
/** * @param Project $project * * @return string */ private function getProjectSlug(Project $project) { return $project->getProviderData('full_slug'); }
private function getGithubInfos(Project $project) { if (!array_key_exists($project->getFullName(), $this->githubInfos)) { $provider = $this->getContainer()->get('app_core.provider.github'); $client = $provider->configureClientForProject($project); $request = $client->get($project->getGithubUrl()); $response = $request->send(); $this->githubInfos[$project->getFullName()] = $response->json(); } return $this->githubInfos[$project->getFullName()]; }
/** * @param Project $project */ protected function doPullRequests(Project $project) { // right now, there's no clean way to checkout bitbucket's pull request, so we're just going to not support them return; // @bitbucketapi sometimes its {owner}, sometimes {accountname} // also, URL is wrong in documentation (is 1.0, should be 2.0) // see https://confluence.atlassian.com/display/BITBUCKET/pullrequests+Resource#pullrequestsResource-GETalistofopenpullrequests $url = sprintf('2.0/repositories/%s/pullrequests?state=OPEN', $project->getFullName()); foreach ($this->fetchPullRequests($url) as $data) { $pr = new PullRequest(); $pr->setNumber($data['id']); $pr->setOpen(true); $pr->setTitle($data['title']); // $pr->setRef(sprintf('pull/%d/head', $data['number'])); $pr->setProject($project); $project->addPullRequest($pr); } }
/** * @todo the policy check and Payload->isBuildable() could be implemented * as a voting system */ private function scheduleBranchPush(PayloadInterface $payload, Project $project) { $logger = $this->get('logger'); $em = $this->get('doctrine')->getManager(); if (!$payload->hasRef()) { return new JsonResponse(json_encode(null), 400); } $ref = $payload->getRef(); $hash = $payload->getHash(); # then, check if ref is configured to be automatically built $doBuild = false; switch ($project->getSettings()->getPolicy()) { case ProjectSettings::POLICY_ALL: $doBuild = true; break; case ProjectSettings::POLICY_NONE: case ProjectSettings::POLICY_PR: $doBuild = false; break; case ProjectSettings::POLICY_PATTERNS: $patterns = explode(PHP_EOL, $project->getSettings()->getBranchPatterns()); foreach ($patterns as $pattern) { $regex = strtr($pattern, ['*' => '.*', '?' => '.']); if (preg_match('/' . $regex . '/i', $ref)) { $doBuild = true; } } break; default: $logger->error('could not find a build policy', ['project' => $project->getId(), 'ref' => $ref]); return new JsonResponse(['class' => 'danger', 'message' => 'Could not find a build policy'], 400); } if (!$doBuild) { $logger->info('build declined by project policy', ['project' => $project->getId(), 'ref' => $ref]); return new JsonResponse(['class' => 'info', 'message' => 'Build declined by project policy (' . $project->getSettings()->getPolicy() . ')'], 200); } /** @todo this should be in the PayloadInterface as ->isDelete() or something */ if ($hash === '0000000000000000000000000000000000000000') { $branch = $em->getRepository('Model:Branch')->findOneByProjectAndName($project, $ref); $branch->setDeleted(true); $em->persist($branch); $em->flush(); return new JsonResponse(json_encode(null), 200); } $sameHashBuilds = $em->getRepository('Model:Build')->findByHash($hash); if (count($sameHashBuilds) > 0) { $logger->warn('found builds with same hash', ['count' => count($sameHashBuilds)]); $allowRebuild = array_reduce($sameHashBuilds, function ($result, $b) { return $result || $b->getAllowRebuild(); }, false); } if (isset($allowRebuild) && !$allowRebuild) { $logger->warn('build already scheduled for hash', ['hash' => $hash]); return new JsonResponse(['class' => 'danger', 'message' => 'Build already scheduled for hash'], 400); } else { $logger->info('scheduling build for hash', ['hash' => $hash]); } return [$ref, $hash]; }
private function fixProvider(OutputInterface $output, Project $project) { if (strlen($project->getProviderName()) > 0) { $output->writeln('project <info>' . $project->getFullName() . '</info> already migrated'); return false; } $output->writeln('migrating project <info>' . $project->getFullName() . '</info>'); $project->setFullName($project->getGithubFullName()); $project->setProviderName('github'); $project->setProviderData(['clone_url' => $project->getCloneUrl(), 'ssh_url' => $project->getSshUrl(), 'keys_url' => $project->getKeysUrl(), 'hooks_url' => $project->getHooksUrl(), 'contents_url' => $project->getContentsUrl(), 'id' => $project->getGithubId(), 'full_name' => $project->getGithubFullName(), 'owner_login' => $project->getGithubOwnerLogin(), 'hook_id' => $project->getGithubHookId(), 'deploy_key_id' => $project->getGithubDeployKeyId(), 'private' => $project->getGithubPrivate(), 'url' => $project->getGithubUrl()]); return true; }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { try { $this->validate($request, ['project_name' => 'required|max:255|min:3', 'project_desc' => 'required|min:1|max:500']); $ispublic = $request->input('is_public') ? true : false; $isactive = $request->input('is_active') ? true : false; $projectobj = new Project(); $projectobj->where('id', $id)->update(['project_name' => $request->input('project_name'), 'project_desc' => $request->input('project_desc'), 'is_public' => $ispublic, 'is_active' => $isactive]); if ($request->input('fileId') != '' && $request->input('fileId') != null) { $fileIdArr = explode(' ', $request->input('fileId')); foreach ($fileIdArr as $fileId) { Files::where('id', $fileId)->update(['attachment_id' => $request->input('id')]); } } //update attachment images if ($request->has('img')) { foreach ($request->input('img') as $img) { //unserialize image value $imgVal = unserialize($img); if ($imgVal[1]) { $fileObj = new Files(); $fileObj->where('id', $imgVal[0])->update(['attachment_id' => $id]); } else { $fileObj = new Files(); $fileObj->where('id', $imgVal[0])->update(['is_active' => false]); } } } return Redirect::to("/back/project/edit/{$id}")->with('message', $request->input('project_name') . ' was successfully updated'); } catch (Exception $e) { return Redirect::to("/back/project/edit/{$id}")->with('message', 'Oops! Something went wrong. Please try again later'); } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { /** @var Project $project */ $project = Project::findOrFail($id); /** @var Ticket $ticket */ foreach ($project->tickets()->get() as $ticket) { $ticket->delete(); } $project->delete(); return redirect('projects'); }
private function getAccessForm(Project $project) { return $this->createForm('project_access', new ProjectAccess(), ['action' => $this->generateUrl('app_core_project_access_create', ['id' => $project->getId()]), 'method' => 'POST']); }
public static function project_data($num, $order = null, $where = null, $type = 0, $offset = 0) { $num = intval($num); $offset = intval($offset); $key = 'project_' . $num . '_' . $order . '_' . $where . '_' . $type . '_' . $offset; if (Cache::store('project')->has($key)) { $date = Cache::store('project')->get($key); return $date; } else { switch ($order) { case byId: $order_str = 'id'; break; case bySort: $order_str = 'sort'; break; case byViews: $order_str = 'views'; break; case byCost: $order_str = 'cost'; break; default: $order_str = 'id'; break; } $type = intval($type); switch ($where) { case findAll: $date = Project::sortByDesc($order_str)->take($num)->Offset($offset)->get(); break; case findRecommend: $date = Project::where('is_recommend', '>', 0)->sortByDesc($order_str)->take($num)->Offset($offset)->get(); break; case findCategory: $date = Project::where('category_id', $type)->orderBy($order_str, 'desc')->take($num)->Offset($offset)->get(); break; default: $date = Project::sortByDesc($order_str)->take($num)->Offset($offset)->get(); break; } $expiresAt = Carbon::now()->addMinutes(60); //设置缓存时间 Cache::store('project')->put($key, $date, $expiresAt); return $date; } }
public function destroy($id) { Project::destroy($id); Cache::store('project')->flush(); return ['error' => 0, 'message' => '删除成功!']; }
/** * プロジェクト削除(Ajax) */ public function postDelete(Request $request) { $this->isAjax($request); $result = DB::transaction(function () use($request) { // プロジェクト削除 $project = Project::findOrFail($request->id); $project->delete(); return $project->id; }); return \Response::json($result); }
public function getProvider(Project $project) { return $this->getProviderByName($project->getProviderName()); }