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

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
demos
#www/images/programs
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 $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) {
$this->username = $usr_name;
}
@ -44,6 +50,14 @@ class ExtendedGitGraph {
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) {
$this->token = $token;
$this->tokenHeader = 'access_token=' . $token . '&token_type=bearer';
@ -117,7 +131,23 @@ class ExtendedGitGraph {
}
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);
$response = @file_get_contents($url, false, $context);
@ -214,29 +244,36 @@ class ExtendedGitGraph {
'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');
}
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_commit();
$_SESSION[self::PROGRESS_SESSION_COOKIE] = '';
session_commit();
}
}
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_commit();
$_SESSION[self::PROGRESS_SESSION_COOKIE] .= '[' . date('H:i.s') . '] ' . $txt . "\r\n";
session_commit();
} else {
print $txt;
print "\n";
}
}
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->commits = $data['commits'];
@ -265,7 +302,7 @@ class ExtendedGitGraph {
$this->generateCommitMap();
file_put_contents(self::FILE_FINISHED_DATA,
file_put_contents($this->FILE_FINISHED_DATA,
serialize(
[
'creation' => new DateTime(),
@ -490,12 +527,12 @@ class ExtendedGitGraph {
}
public function loadFinishedContent() {
$data = unserialize(file_get_contents(self::FILE_FINISHED_DATA));
$data = unserialize(file_get_contents($this->FILE_FINISHED_DATA));
return $data['content'];
}
public function loadFinishedData() {
$data = unserialize(file_get_contents(self::FILE_FINISHED_DATA));
$data = unserialize(file_get_contents($this->FILE_FINISHED_DATA));
return $data;
}

View File

@ -1,37 +1,64 @@
<?php
// This is the configuration for yiic console application.
// Any writable CConsoleApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Console Application',
return [
'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
'name' => 'Mikescher.com - Console',
// preloading 'log' component
'preload'=>array('log'),
// preloading 'log' component
'preload' =>
[
'log'
],
// application components
'components'=>array(
'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),
// uncomment the following to use a MySQL database
/*
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=testdrive',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
*/
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
),
),
),
);
'aliases' =>
[
'bootstrap' => realpath(__DIR__ . '/../extensions/bootstrap'), // change this if necessary
],
// autoloading model and component classes
'import' =>
[
'application.models.*',
'application.extensions.*',
'application.components.*',
'application.components.widgets.*',
'application.components.extendedgitgraph.*',
'application.components.parsedown.*',
'bootstrap.components.*',
'bootstrap.behaviors.*',
'bootstrap.helpers.*',
'bootstrap.widgets.*',
],
'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_',
],
'counter' => array(
'class' => 'UserCounter',
),
'counter' =>
[
'class' => 'UserCounter',
],
],
// application-level parameters that can be accessed

View File

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