1
0

Added EGH command (called by cron)

This commit is contained in:
Mike Schwörer 2016-01-02 00:10:25 +01:00
parent 86bad2a1c9
commit 3bb7db5545
6 changed files with 146 additions and 50 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
.idea .idea
demos demos
#www/images/programs #www/images/programs
workspace.xml workspace.xml
*.secret

View File

@ -0,0 +1,30 @@
<?php
include 'ExtendedGitGraph.php';
class EGH_RefreshCommand extends CConsoleCommand
{
public function run($args)
{
$v = new ExtendedGitGraph('Mikescher');
$v->setSessionOutput(false);
$v->setRawDataPath('/var/www/website/www/protected/data/git_graph_raw.dat');
$v->setFinDataPath('/var/www/website/www/protected/data/git_graph_data.dat');
$v->setToken(file_get_contents('/var/www/website/www/protected/commands/github.token.secret'));
//##########################################################
$v->addSecondaryUsername("Sam-Development");
$v->addSecondaryRepository("Anastron/ColorRunner");
//##########################################################
//$v->setToken(file_get_contents('api_token.secret'));
$v->collect();
//##########################################################
$v->generateAndSave();
}
}

View File

@ -30,6 +30,12 @@ class ExtendedGitGraph {
private $startdate = null; private $startdate = null;
private $enddate = null; private $enddate = null;
private $sessionOutput = true;
private $basicAuth = null;
private $FILE_RAW_DATA = 'protected/data/git_graph_raw.dat';
private $FILE_FINISHED_DATA = 'protected/data/git_graph_data.dat';
public function __construct($usr_name) { public function __construct($usr_name) {
$this->username = $usr_name; $this->username = $usr_name;
} }
@ -44,6 +50,14 @@ class ExtendedGitGraph {
setToken($result); setToken($result);
} }
public function setSessionOutput($sout) { $this->sessionOutput = $sout; }
public function setRawDataPath($rdp) { $this->FILE_RAW_DATA = $rdp; }
public function setFinDataPath($fdp) { $this->FILE_FINISHED_DATA = $fdp; }
public function setBasicAuthentication($usr, $passw) { $this->basicAuth = "Authorization: Basic " . base64_encode($usr . ":" . $passw); }
public function setToken($token) { public function setToken($token) {
$this->token = $token; $this->token = $token;
$this->tokenHeader = 'access_token=' . $token . '&token_type=bearer'; $this->tokenHeader = 'access_token=' . $token . '&token_type=bearer';
@ -117,7 +131,23 @@ class ExtendedGitGraph {
} }
private function getJSON($url) { private function getJSON($url) {
$options = array('http' => array('user_agent'=> $_SERVER['HTTP_USER_AGENT'])); if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) {
$options = ['http' => ['user_agent'=> $_SERVER['HTTP_USER_AGENT']]];
} else {
$options = ['http' => ['user_agent'=> 'ExtendedGitGraph_for_mikescher.com']];
}
if ($this->basicAuth != null) {
$options =
[
'http' =>
[
'user_agent' => $options['http']['user_agent'],
'header' => $this->basicAuth,
]
];
}
$context = stream_context_create($options); $context = stream_context_create($options);
$response = @file_get_contents($url, false, $context); $response = @file_get_contents($url, false, $context);
@ -214,29 +244,36 @@ class ExtendedGitGraph {
'commits' => $this->commits, 'commits' => $this->commits,
]); ]);
file_put_contents(self::FILE_RAW_DATA, $save); file_put_contents($this->FILE_RAW_DATA, $save);
$this->output_flushed('Finished saving data'); $this->output_flushed('Finished saving data');
} }
public function output_flushed_clear() public function output_flushed_clear()
{ {
if (session_status() !== PHP_SESSION_ACTIVE) session_start(); if ($this->sessionOutput) {
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
$_SESSION[self::PROGRESS_SESSION_COOKIE] = ''; $_SESSION[self::PROGRESS_SESSION_COOKIE] = '';
session_commit(); session_commit();
}
} }
public function output_flushed($txt) public function output_flushed($txt)
{ {
if (session_status() !== PHP_SESSION_ACTIVE) session_start(); if ($this->sessionOutput) {
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
$_SESSION[self::PROGRESS_SESSION_COOKIE] .= '[' . date('H:i.s') . '] ' . $txt . "\r\n"; $_SESSION[self::PROGRESS_SESSION_COOKIE] .= '[' . date('H:i.s') . '] ' . $txt . "\r\n";
session_commit(); session_commit();
} else {
print $txt;
print "\n";
}
} }
public function loadData() { public function loadData() {
$data = unserialize(file_get_contents(self::FILE_RAW_DATA)); $data = unserialize(file_get_contents($this->FILE_RAW_DATA));
$this->repositories = $data['repositories']; $this->repositories = $data['repositories'];
$this->commits = $data['commits']; $this->commits = $data['commits'];
@ -265,7 +302,7 @@ class ExtendedGitGraph {
$this->generateCommitMap(); $this->generateCommitMap();
file_put_contents(self::FILE_FINISHED_DATA, file_put_contents($this->FILE_FINISHED_DATA,
serialize( serialize(
[ [
'creation' => new DateTime(), 'creation' => new DateTime(),
@ -490,12 +527,12 @@ class ExtendedGitGraph {
} }
public function loadFinishedContent() { public function loadFinishedContent() {
$data = unserialize(file_get_contents(self::FILE_FINISHED_DATA)); $data = unserialize(file_get_contents($this->FILE_FINISHED_DATA));
return $data['content']; return $data['content'];
} }
public function loadFinishedData() { public function loadFinishedData() {
$data = unserialize(file_get_contents(self::FILE_FINISHED_DATA)); $data = unserialize(file_get_contents($this->FILE_FINISHED_DATA));
return $data; return $data;
} }

View File

@ -1,37 +1,64 @@
<?php <?php
// This is the configuration for yiic console application. return [
// Any writable CConsoleApplication properties can be configured here. 'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
return array( 'name' => 'Mikescher.com - Console',
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Console Application',
// preloading 'log' component // preloading 'log' component
'preload'=>array('log'), 'preload' =>
[
'log'
],
// application components 'aliases' =>
'components'=>array( [
'db'=>array( 'bootstrap' => realpath(__DIR__ . '/../extensions/bootstrap'), // change this if necessary
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db', ],
),
// uncomment the following to use a MySQL database // autoloading model and component classes
/* 'import' =>
'db'=>array( [
'connectionString' => 'mysql:host=localhost;dbname=testdrive', 'application.models.*',
'emulatePrepare' => true, 'application.extensions.*',
'username' => 'root', 'application.components.*',
'password' => '', 'application.components.widgets.*',
'charset' => 'utf8', 'application.components.extendedgitgraph.*',
), 'application.components.parsedown.*',
*/ 'bootstrap.components.*',
'log'=>array( 'bootstrap.behaviors.*',
'class'=>'CLogRouter', 'bootstrap.helpers.*',
'routes'=>array( 'bootstrap.widgets.*',
array( ],
'class'=>'CFileLogRoute',
'levels'=>'error, warning', 'modules' =>
), [
), //
), ],
),
); // application components
'components' =>
[
'log' =>
[
'class' => 'CLogRouter',
'routes' =>
[
[
'class' => 'CFileLogRoute',
'levels' => 'error, warning',
],
],
],
],
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params' =>
[
'yii.debug' => defined('YII_DEBUG'),
'yii.traceLevel' => 3,
'yii.handleErrors' => defined('YII_DEBUG'),
// this is used in contact page
'adminEmail' => 'kundenservice@mikescher.de',
],
];

View File

@ -140,9 +140,10 @@ return ArrayX::merge(
'tablePrefix' => 'ms4_', 'tablePrefix' => 'ms4_',
], ],
'counter' => array( 'counter' =>
'class' => 'UserCounter', [
), 'class' => 'UserCounter',
],
], ],
// application-level parameters that can be accessed // application-level parameters that can be accessed

View File

@ -3,11 +3,11 @@
include 'extendedGitGraph.php'; include 'extendedGitGraph.php';
$v = new ExtendedGitGraph('Mikescher'); $v = new ExtendedGitGraph('Mikescher');
$v->setSessionOutput(true);
//########################################################## //##########################################################
$v->addSecondaryUsername("Sam-Development"); $v->addSecondaryUsername("Sam-Development");
$v->addSecondaryRepository("Anastron/ColorRunner"); $v->addSecondaryRepository("Anastron/ColorRunner");
//########################################################## //##########################################################