Пример #1
0
 /**
  * Send status updates to any relevant third parties (i.e. Github)
  */
 public function sendStatusPostback()
 {
     $token = \b8\Config::getInstance()->get('phpci.github.token');
     if (empty($token)) {
         return;
     }
     $project = $this->getProject();
     $url = 'https://api.github.com/repos/' . $project->getReference() . '/statuses/' . $this->getCommitId();
     $http = new \b8\HttpClient();
     switch ($this->getStatus()) {
         case 0:
         case 1:
             $status = 'pending';
             break;
         case 2:
             $status = 'success';
             break;
         case 3:
             $status = 'failure';
             break;
         default:
             $status = 'error';
             break;
     }
     $phpciUrl = \b8\Config::getInstance()->get('phpci.url');
     $params = array('state' => $status, 'target_url' => $phpciUrl . '/build/view/' . $this->getId());
     $headers = array('Authorization: token ' . $token, 'Content-Type: application/x-www-form-urlencoded');
     $http->setHeaders($headers);
     $http->request('POST', $url, json_encode($params));
 }
Пример #2
0
 protected function init()
 {
     if (empty($this->blobProxy)) {
         $config = Config::getInstance()->get('Octo.Azure.BlobStorage');
         $this->blobProxy = ServicesBuilder::getInstance()->createBlobService($config['ConnectionString']);
     }
 }
Пример #3
0
 protected function getAssetCode()
 {
     /** @var \b8\Config */
     $config = Config::getInstance();
     $paths = $config->get('Octo.paths.modules');
     /** @var \Octo\AssetManager $assets */
     $assets = $config->get('Octo.AssetManager');
     $inject = ['css' => '', 'js' => ''];
     foreach ($assets->getCss() as $css) {
         $path = $paths[$css['module']] . 'Public/css/' . $css['name'] . '.css';
         if (is_file($path)) {
             $href = $config->get('site.url') . '/asset/css/' . $css['module'] . '/' . $css['name'] . '?t=' . filemtime($path);
             $inject['css'] .= '<link rel="stylesheet" type="text/css" href="' . $href . '">';
         }
     }
     foreach ($assets->getExternalJs() as $js) {
         $inject['js'] .= '<script src="' . $js . '"></script>';
     }
     foreach ($assets->getJs() as $js) {
         $path = $paths[$js['module']] . 'Public/js/' . $js['name'] . '.js';
         if (is_file($path)) {
             $href = $config->get('site.url') . '/asset/js/' . $js['module'] . '/' . $js['name'] . '?t=' . filemtime($path);
             $inject['js'] .= '<script src="' . $href . '"></script>';
         }
     }
     return $inject;
 }
Пример #4
0
 /**
  * Get an array of repositories from Github's API.
  */
 public function getRepositories()
 {
     $token = Config::getInstance()->get('phpci.github.token');
     if (!$token) {
         die(json_encode(null));
     }
     $cache = Cache::getCache(Cache::TYPE_APC);
     $rtn = $cache->get('phpci_github_repos');
     if (!$rtn) {
         $orgs = $this->makeRequest('/user/orgs', array('access_token' => $token));
         $params = array('type' => 'all', 'access_token' => $token);
         $repos = array('user' => array());
         $repos['user'] = $this->makeRecursiveRequest('/user/repos', $params);
         foreach ($orgs as $org) {
             $repos[$org['login']] = $this->makeRecursiveRequest('/orgs/' . $org['login'] . '/repos', $params);
         }
         $rtn = array();
         foreach ($repos as $repoGroup) {
             foreach ($repoGroup as $repo) {
                 $rtn['repos'][] = $repo['full_name'];
             }
         }
         $cache->set('phpci_github_repos', $rtn);
     }
     return $rtn;
 }
Пример #5
0
 /**
  * Checks if 
  * @param $method
  * @param array $params
  * @return mixed|null
  */
 public function __call($method, $params = array())
 {
     unset($method, $params);
     $config = Config::getInstance();
     $state = (bool) $config->get('phpci.authentication_settings.state', false);
     return false !== $state;
 }
Пример #6
0
 protected function onPreRender(&$view)
 {
     /** @var \Octo\AssetManager $assets */
     $assets = Config::getInstance()->get('Octo.AssetManager');
     $assets->addExternalJs('//cdnjs.cloudflare.com/ajax/libs/jquery.payment/1.3.2/jquery.payment.min.js');
     parent::onPreRender($view);
 }
Пример #7
0
 protected function controllerExists($route)
 {
     $namespace = $this->toPhpName($route['namespace']);
     $controller = $this->toPhpName($route['controller']);
     $appNs = $this->config->get('b8.app.namespace');
     $controllerClass = $appNs . '\\' . $namespace . '\\' . $controller . 'Controller';
     return class_exists($controllerClass);
 }
Пример #8
0
 protected function onPreRender(&$view)
 {
     parent::onPreRender($view);
     /** @var \Octo\AssetManager $assets */
     $assets = Config::getInstance()->get('Octo.AssetManager');
     $assets->addJs('Forms', 'phoneformat');
     $view->type = 'tel';
 }
Пример #9
0
 protected function getPath($module)
 {
     if ($module == 'site') {
         $siteNamespace = $this->config->get('site.namespace');
         return APP_PATH . $siteNamespace . '/Public/';
     }
     $paths = Config::getInstance()->get('Octo.paths.modules');
     return $paths[$module] . 'Public/';
 }
Пример #10
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!OCTO_QUEUE_ENABLED) {
         $error = 'The worker is not configured. You must set a worker host in your site config file.';
         throw new \Exception($error);
     }
     $worker = new Worker(Config::getInstance()->get('Octo.worker.host'));
     $worker->run($input->getOption('verbose'));
 }
Пример #11
0
 public static function exists($type)
 {
     $config = \b8\Config::getInstance();
     $block = $config->get('Octo.namespaces.blocks.' . $type);
     if (!empty($block)) {
         return true;
     }
     return false;
 }
Пример #12
0
 /**
  * @param $store
  *
  * @return \b8\Store;
  */
 public function loadStore($store, $namespace = null)
 {
     if (!isset($this->loadedStores[$store])) {
         $namespace = is_null($namespace) ? Config::getInstance()->get('b8.app.namespace') : $namespace;
         $class = $namespace . '\\Store\\' . $store . 'Store';
         $obj = new $class();
         $this->loadedStores[$store] = $obj;
     }
     return $this->loadedStores[$store];
 }
Пример #13
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     unset($input, $output);
     $connection = Database::getConnection();
     $namespaces = Config::getInstance()->get('app.namespaces');
     $paths = Config::getInstance()->get('Octo.paths.namespaces');
     $gen = new Database\CodeGenerator($connection, $namespaces, $paths, true);
     $gen->generateModels();
     $gen->generateStores();
 }
Пример #14
0
 public function init()
 {
     $this->config = Config::getInstance();
     $siteModules = array_reverse($this->config->get('ModuleManager')->getEnabled());
     foreach ($siteModules as $namespace => $modules) {
         foreach ($modules as $module) {
             $path = $this->config->get('Octo.paths.modules.' . $module, '') . 'Event/';
             $this->registerListeners($path, $namespace . '\\' . $module . '\\Event\\');
         }
     }
 }
Пример #15
0
 public function img($module)
 {
     $parts = array_slice(func_get_args(), 1);
     $name = implode('/', $parts);
     $paths = Config::getInstance()->get('Octo.paths.modules');
     $path = $paths[$module] . 'Public/img/' . $name;
     if (!file_exists($path)) {
         throw new NotFoundException('Asset ' . $module . '::' . $name . ' does not exist.');
     }
     $this->response->disableLayout();
     return file_get_contents($path);
 }
Пример #16
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     unset($input, $output);
     $c = Config::getInstance();
     $connection = Connection::get();
     $namespaces = $c->get('app.namespaces');
     $paths = $c->get('Octo.paths.namespaces');
     $mapper = new Mapper($connection);
     $gen = new CodeGenerator($mapper, $namespaces, $paths);
     $gen->generateModels();
     $gen->generateStores();
 }
Пример #17
0
 /**
  * Setup the menus for each controller
  */
 protected function setupControllerMenus()
 {
     $this->config = Config::getInstance();
     $paths = Config::getInstance()->get('Octo.paths.namespaces');
     foreach ($paths as $namespace => $path) {
         $thisPath = $path . 'Admin/Controller/*.php';
         $files = glob($thisPath);
         foreach ($files as $file) {
             $this->getControllerMenuItems($file, $namespace);
         }
     }
 }
Пример #18
0
 public static function delete(Job $job)
 {
     if ($job->getQueueId()) {
         $pheanstalk = new Pheanstalk(Config::getInstance()->get('Octo.worker.host'));
         try {
             $beanstalkJob = $pheanstalk->peek($job->getQueueId());
             $pheanstalk->delete($beanstalkJob);
         } catch (\Exception $ex) {
             // Job is not in beanstalk.
         }
     }
     self::getStore()->delete($job);
 }
Пример #19
0
 public function getValue()
 {
     if (array_key_exists($this->getName(), $_FILES)) {
         $extension = substr($_FILES[$this->getName()]['name'], strrpos($_FILES[$this->getName()]['name'], '.'));
         $filename = '/uploads/' . md5(file_get_contents($_FILES[$this->getName()]['tmp_name'])) . $extension;
         $path = APP_PATH . 'public' . $filename;
         move_uploaded_file($_FILES[$this->getName()]['tmp_name'], $path);
         $url = Config::getInstance()->get('site.url') . $filename;
         $this->uploadedName = $_FILES[$this->getName()]['name'];
         $this->uploadedPath = $path;
         return $url;
     }
     return null;
 }
Пример #20
0
 public static function getPath($template, $module = null)
 {
     $config = Config::getInstance();
     $paths = array_reverse($config->get('Octo.paths.' . static::$templateType, []));
     foreach ($paths as $moduleName => $path) {
         if (!is_null($module) && $moduleName !== $module) {
             $path .= $module . '/';
         }
         if (file_exists($path . $template . '.html')) {
             return $path;
         }
     }
     return null;
 }
Пример #21
0
 public static function getClass($controller)
 {
     $config = Config::getInstance();
     $siteModules = $config->get('ModuleManager')->getEnabled();
     foreach ($siteModules as $namespace => $modules) {
         foreach ($modules as $module) {
             $class = "\\{$namespace}\\{$module}\\Controller\\{$controller}Controller";
             if (class_exists($class)) {
                 return $class;
             }
         }
     }
     return null;
 }
Пример #22
0
 public function run()
 {
     $data = $this->job->getData();
     $config = Config::getInstance();
     $mail = new \PHPMailer();
     // Enable SMTP if required:
     if (isset($config->site['smtp_server'])) {
         $mail->IsSMTP();
         $mail->SMTPAuth = true;
         $mail->Host = $config->get('site.smtp_server', null);
         $mail->Username = $config->get('site.smtp_username', null);
         $mail->Password = $config->get('site.smtp_password', null);
     }
     // Is this email a HTML email?
     $mail->IsHTML(false);
     if (!empty($data['html']) && $data['html']) {
         $mail->IsHTML(true);
     }
     $mail->Subject = $data['subject'];
     $mail->CharSet = "UTF-8";
     // Handle recipients and CCs:
     foreach ($data['to'] as $recipient) {
         $mail->addAddress($recipient['email'], $recipient['name']);
     }
     if (isset($data['cc']) && is_array($data['cc'])) {
         foreach ($data['cc'] as $recipient) {
             $mail->addCc($recipient['email'], $recipient['name']);
         }
     }
     // Handle Reply To:
     if (isset($data['reply_to']) && is_array($data['reply_to'])) {
         $mail->addReplyTo($data['reply_to']['email'], $data['reply_to']['name']);
     }
     // Handle From:
     if (isset($config->site['email_from'])) {
         $mail->SetFrom($config->site['email_from'], $config->site['email_from_name']);
     }
     // Handle attachments:
     if (isset($data['attachments']) && is_array($data['attachments'])) {
         foreach ($data['attachments'] as $name => $path) {
             $mail->addAttachment($path, $name);
         }
     }
     $mail->Body = $data['body'];
     if (!$mail->send()) {
         throw new Exception($mail->ErrorInfo);
     }
     return true;
 }
Пример #23
0
 public static function registerMenus(Menu $menu)
 {
     /** @var \Octo\AssetManager $assets */
     $assets = Config::getInstance()->get('Octo.AssetManager');
     $assets->addJs('System', 'contact');
     $thisMenu = $menu->addRoot('Contacts', '/contact')->setIcon('users');
     $thisMenu->addChild(new Menu\Item('Add Contact', '/contact/add'));
     $thisMenu->addChild(new Menu\Item('Contact Popup', '/contact/popup', true));
     $thisMenu->addChild(new Menu\Item('Manage Contacts', '/contact'));
     $thisMenu->addChild(new Menu\Item('Edit Contact', '/contact/edit', true));
     $thisMenu->addChild(new Menu\Item('Contact Autocomplete', '/contact/autocomplete', true));
     $thisMenu->addChild(new Menu\Item('Contact Autocomplete', '/contact/autocomplete', true));
     $thisMenu->addChild(new Menu\Item('Block Contact', '/contact/block', true));
     $thisMenu->addChild(new Menu\Item('Unblock Contact', '/contact/unblock', true));
 }
Пример #24
0
 public function __call($method, $params = array())
 {
     if (!isset(self::$helpers[$method])) {
         $class = '\\' . Config::getInstance()->get('b8.app.namespace') . '\\Helper\\' . $method;
         if (!class_exists($class)) {
             $class = '\\b8\\View\\Helper\\' . $method;
         }
         if (!class_exists($class)) {
             throw new HttpException('Helper class does not exist: ' . $class);
         }
         self::$helpers[$method] = new $class($params);
         self::$helpers[$method]->view = $this;
     }
     return self::$helpers[$method];
 }
Пример #25
0
 public function init()
 {
     $base = $this->getPath();
     $templatePath = $base . 'Template/';
     $adminTemplatePath = $base . 'Admin/Template/';
     $octoConfig = $this->config->get('Octo', []);
     if (is_dir($templatePath)) {
         $octoConfig['paths']['templates'][$this->getName()] = $templatePath;
     }
     if (is_dir($adminTemplatePath)) {
         $octoConfig['paths']['admin_templates'][$this->getName()] = $adminTemplatePath;
     }
     $octoConfig['paths']['modules'][$this->getName()] = $base;
     $octoConfig['paths']['namespaces'][$this->namespace . '\\' . $this->getName()] = $base;
     if (!isset($octoConfig['namespaces']['blocks'])) {
         $octoConfig['namespaces']['blocks'] = [];
     }
     $blocks = $this->getBlocks($this->namespace);
     $octoConfig['namespaces']['blocks'] = array_merge($octoConfig['namespaces']['blocks'], $blocks);
     $app = $this->config->get('app', []);
     $app['namespaces'] = array_merge($app['namespaces'], $this->getModels($this->namespace));
     $this->config->set('app', $app);
     $this->config->set('Octo', $octoConfig);
 }
Пример #26
0
 /**
  * Get the correct field class for the form
  *
  * @param $type
  * @return null|string
  */
 public static function getFieldClass($type)
 {
     $config = b8\Config::getInstance();
     $try = '\\' . $config->get('site.namespace') . '\\Form\\Element\\' . $type;
     if (class_exists($try)) {
         return $try;
     }
     $try = '\\Octo\\Form\\Element\\' . $type;
     if (class_exists($try)) {
         return $try;
     }
     $try = '\\b8\\Form\\Element\\' . $type;
     if (class_exists($try)) {
         return $try;
     }
     return null;
 }
Пример #27
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->output = $output;
     // For verbose mode we want to output all informational and above
     // messages to the symphony output interface.
     if ($input->hasOption('verbose') && $input->getOption('verbose')) {
         $this->logger->pushHandler(new OutputLogHandler($this->output, Logger::INFO));
     }
     $config = Config::getInstance()->get('phpci.worker', []);
     if (empty($config['host']) || empty($config['queue'])) {
         $error = 'The worker is not configured. You must set a host and queue in your config.yml file.';
         throw new \Exception($error);
     }
     $worker = new BuildWorker($config['host'], $config['queue']);
     $worker->setLogger($this->logger);
     $worker->setMaxJobs(Config::getInstance()->get('phpci.worker.max_jobs', -1));
     $worker->startWorker();
 }
Пример #28
0
 /**
  * Sets up the twig template loader.
  */
 public static function init()
 {
     self::$loader = new Twig_Loader_Filesystem();
     $config = Config::getInstance();
     foreach (array_reverse($config->get('Octo.paths.templates', [])) as $path) {
         self::$loader->addPath($path);
     }
     foreach (array_reverse($config->get('Octo.paths.admin_templates', [])) as $path) {
         self::$loader->addPath($path, 'admin');
     }
     if (OCTO_CACHE_ENABLED) {
         self::$cache = OCTO_CACHE_PATH;
     } else {
         self::$cache = false;
     }
     self::$twig = new Twig_Environment(self::$loader, ['charset' => 'UTF-8', 'cache' => self::$cache, 'auto_reload' => true, 'strict_variables' => false]);
     $functions = [];
     Event::trigger('TemplateInit', $functions);
     foreach ($functions as $name => $callable) {
         self::addFunction($name, $callable);
     }
     self::$initialised = true;
 }
Пример #29
0
 public static function getSessionKey()
 {
     return Config::getInstance()->get('site.namespace', 'octo') . '_member_id';
 }
Пример #30
0
 /**
  * Handle the payload when Github sends a Pull Request webhook.
  *
  * @param Project $project
  * @param array $payload
  */
 protected function githubPullRequest(Project $project, array $payload)
 {
     // We only want to know about open pull requests:
     if (!in_array($payload['action'], array('opened', 'synchronize', 'reopened'))) {
         return array('status' => 'ok');
     }
     $headers = array();
     $token = \b8\Config::getInstance()->get('phpci.github.token');
     if (!empty($token)) {
         $headers[] = 'Authorization: token ' . $token;
     }
     $url = $payload['pull_request']['commits_url'];
     $http = new \b8\HttpClient();
     $http->setHeaders($headers);
     $response = $http->get($url);
     // Check we got a success response:
     if (!$response['success']) {
         throw new Exception('Could not get commits, failed API request.');
     }
     $results = array();
     $status = 'failed';
     foreach ($response['body'] as $commit) {
         // Skip all but the current HEAD commit ID:
         $id = $commit['sha'];
         if ($id != $payload['pull_request']['head']['sha']) {
             $results[$id] = array('status' => 'ignored', 'message' => 'not branch head');
             continue;
         }
         try {
             $branch = str_replace('refs/heads/', '', $payload['pull_request']['base']['ref']);
             $committer = $commit['commit']['author']['email'];
             $message = $commit['commit']['message'];
             $remoteUrlKey = $payload['pull_request']['head']['repo']['private'] ? 'ssh_url' : 'clone_url';
             $extra = array('build_type' => 'pull_request', 'pull_request_id' => $payload['pull_request']['id'], 'pull_request_number' => $payload['number'], 'remote_branch' => $payload['pull_request']['head']['ref'], 'remote_url' => $payload['pull_request']['head']['repo'][$remoteUrlKey]);
             $results[$id] = $this->createBuild($project, $id, $branch, $committer, $message, $extra);
             $status = 'ok';
         } catch (Exception $ex) {
             $results[$id] = array('status' => 'failed', 'error' => $ex->getMessage());
         }
     }
     return array('status' => $status, 'commits' => $results);
 }