Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4f5ff15c authored by thilo's avatar thilo
Browse files

Merge branch 'add-logging' into 'master'

Add logging system

See merge request eelo/LineageOTA!2
parents f3ed5fd9 1b1a2e33
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -41,7 +41,8 @@
  "require": {
    "mikecao/flight": "1.*",
    "julianxhokaxhiu/DotNotation": "dev-master",
    "ext-zip": "*"
    "ext-zip": "*",
    "monolog/monolog": "1.23.*"
  },
  "autoload": {
    "psr-4": {
+6 −1
Original line number Diff line number Diff line
@@ -25,10 +25,15 @@
    require 'vendor/autoload.php';

    use \JX\CmOta\CmOta;
    use Monolog\Logger;
    use Monolog\Handler\StreamHandler;

    $protocol = 'https://';

    $app = new CmOta();
    $logger = new Logger('main');
    $logger->pushHandler(new StreamHandler('LineageOTA.log', Logger::WARNING));

    $app = new CmOta($logger);
    $app
    ->setConfig( 'basePath', $protocol.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']) )
    ->run();
+5 −3
Original line number Diff line number Diff line
@@ -29,13 +29,15 @@

    class CmOta {
        private $builds = NULL;
        private $logger = null;

        /**
         * Constructor of the CmOta class.
         * @param array $options Various options that can be configured
         */
        public function __construct() {
        public function __construct($logger) {
            // Internal Initialization routines
            $this->logger = $logger;
            $this->initConfig();
            $this->initRouting();
            $this->initBuilds();
@@ -144,7 +146,7 @@
         * Register the build class within Flight
         */
        private function initBuilds() {
            Flight::register( 'builds', '\JX\CmOta\Helpers\Builds', array(), function( $builds ) {
            Flight::register( 'builds', '\JX\CmOta\Helpers\Builds', array($this->logger), function( $builds ) {
                // Do nothing for now
            });
        }
+4 −1
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
        private $buildProp = '';
        private $uid = null;
        private $size = '';
        private $logger = null;

        /**
         * Constructor of the Build class.
@@ -48,7 +49,9 @@
         * @param type $fileName The current filename of the build
         * @param type $physicalPath The current path where the build lives
         */
    	public function __construct($fileName, $physicalPath) {
    	public function __construct($fileName, $physicalPath, $logger) {
        $this->logger = $logger;

    		/*
				$tokens Schema:

+6 −3
Original line number Diff line number Diff line
@@ -33,11 +33,14 @@
    	private $builds = array();

        private $postData = array();
        private $logger = null;

        /**
         * Constructor of the Builds class.
         */
    	public function __construct() {
    	public function __construct($logger) {
            $this->logger = $logger;

            // Set required paths for properly builds Urls later
            Flight::cfg()->set( 'buildsPath', Flight::cfg()->get('basePath') . '/builds/full' );
            Flight::cfg()->set( 'deltasPath', Flight::cfg()->get('basePath') . '/builds/delta' );
@@ -145,12 +148,12 @@

                                // If not found there, we have to find it with the old fashion method...
                                if ( $build === FALSE ) {
                                    $build = new Build( $file, $dir );
                                    $build = new Build( $file, $dir, $this->logger);
                                    // ...and then save it for 72h until it expires again
                                    apcu_store( $file, $build, 72*60*60 );
                                }
                            } else
                                $build = new Build( $file, $dir );
                                $build = new Build( $file, $dir, $this->logger);

                            if ( $build->isValid( $this->postData['params'] ) ) {
                                array_push( $this->builds , $build );