File indexing completed on 2024-05-12 05:58:32

0001 <?php
0002 
0003 /**
0004  *  ocs-webserver
0005  *
0006  *  Copyright 2016 by pling GmbH.
0007  *
0008  *    This file is part of ocs-webserver.
0009  *
0010  *    This program is free software: you can redistribute it and/or modify
0011  *    it under the terms of the GNU Affero General Public License as
0012  *    published by the Free Software Foundation, either version 3 of the
0013  *    License, or (at your option) any later version.
0014  *
0015  *    This program is distributed in the hope that it will be useful,
0016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018  *    GNU Affero General Public License for more details.
0019  *
0020  *    You should have received a copy of the GNU Affero General Public License
0021  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0022  **/
0023 class Backend_PploadController extends Local_Controller_Action_CliAbstract
0024 {
0025 
0026     /**
0027      * cronjob command
0028      * 0   1 * * * /usr/bin/php /var/www/pling.it/pling/scripts/cron.php -a /backend/ppload/run/ >> /var/www/pling.it/logs/stat_downloads.log 2>&1
0029      */
0030     public function runAction()
0031     {
0032         $this->updatePploadDownloadStat();
0033         $this->updateProjectDownloadStat();
0034     }
0035 
0036     protected function updatePploadDownloadStat()
0037     {
0038         $sql = "
0039         TRUNCATE ppload.stat_collection_download;
0040         INSERT INTO ppload.stat_collection_download
0041         SELECT 
0042             collection_id, count(*) as amount
0043         FROM
0044             ppload.ppload_files_downloaded_unique as ppfd
0045         WHERE 
0046           ppfd.downloaded_timestamp > DATE_ADD(CURDATE(), INTERVAL - 3 MONTH)
0047         GROUP BY ppfd.collection_id
0048         ORDER BY amount DESC;
0049         ";
0050         Zend_Db_Table::getDefaultAdapter()->query($sql);
0051     }
0052 
0053     protected function updateProjectDownloadStat()
0054     {
0055         $sql = "
0056         TRUNCATE stat_downloads_quarter_year;
0057         INSERT INTO stat_downloads_quarter_year
0058         SELECT p.project_id, p.project_category_id, p.ppload_collection_id, scd.amount, pc.title as category_title
0059         FROM project as p
0060         JOIN ppload.stat_collection_download as scd on p.ppload_collection_id = scd.collection_id
0061         JOIN project_category as pc using (project_category_id)
0062         ORDER BY p.project_category_id ASC, scd.amount DESC
0063         ;
0064         ";
0065         Zend_Db_Table::getDefaultAdapter()->query($sql);
0066     }
0067 
0068 }