<commit_before><?php

/**
 *  ocs-webserver
 *
 *  Copyright 2016 by pling GmbH.
 *
 *    This file is part of ocs-webserver.
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Affero General Public License as
 *    published by the Free Software Foundation, either version 3 of the
 *    License, or (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Affero General Public License for more details.
 *
 *    You should have received a copy of the GNU Affero General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/
class Default_Model_DbTable_PploadFiles extends Local_Model_Table
{
    /** @var  Zend_Cache_Core */
    protected $cache;
    
    protected $_name = "ppload.ppload_files";

    protected $_keyColumnsForRow = array('id');

    protected $_key = 'id';

    


    /**
     * @inheritDoc
     */
    public function init()
    {
        parent::init(); // TODO: Change the autogenerated stub
        $this->cache = Zend_Registry::get('cache');
    }
    
    
    /**
     * @param int $projectId Description   
     * @return array
     */
    public function fetchFilesForProject($collection_id)
    {

        if(empty($collection_id)) {
            return null;
        }
        
        $sql = " select f.*, pf.id as ppload_file_preview_id, pf.url_preview, pf.url_thumb 
                     from ppload.ppload_files f 
                     LEFT JOIN ppload.ppload_file_preview pf ON pf.collection_id = f.collection_id AND pf.file_id = f.id
                     where f.collection_id = :collection_id     
                     order by f.created_timestamp desc               
                   ";        
        /*
        $sql = " select * 
                     ,
                     (select tag.tag_fullname from tag_object, tag where tag_type_id = 3 and tag_group_id = 8 and tag_object.tag_id = tag.tag_id and tag_object.is_deleted = 0
                     and tag_object_id = f.id ) packagename
                    ,
                    (select tag.tag_fullname from tag_object, tag where tag_type_id = 3 and tag_group_id = 9 and tag_object.tag_id = tag.tag_id and tag_object.is_deleted = 0
                    and tag_object_id = f.id ) archname

                     from ppload.ppload_files f 
                     where f.collection_id = :collection_id     
                     order by f.created_timestamp desc               
                   ";        
         * 
         */
        $result = $this->_db->query($sql,array('collection_id' => $collection_id))->fetchAll();      
        return $result;
    }        

    public function fetchFilesCntForProject($collection_id)
    {

        if(empty($collection_id)) {
            return 0;
        }
        
        $sql = " select  count(1) as cnt
                     from ppload.ppload_files f 
                     where f.collection_id = :collection_id and f.active = 1                  
                   ";        
        $result = $this->_db->query($sql,array('collection_id' => $collection_id))->fetchAll();      
        return $result[0]['cnt'];
    }     
    
    
    public function fetchCountDownloadsTodayForProject($collection_id)
    {
        if(empty($collection_id)) {
            return 0;
        }
        
        $today = (new DateTime())->modify('-1 day');
        $filterDownloadToday = $today->format("Y-m-d H:i:s");

        $this->_db->query("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED")->execute();

        $this->_db->beginTransaction();
        
        $sql = "    SELECT COUNT(1) AS cnt
                    FROM ppload.ppload_files_downloaded f
                    WHERE f.collection_id = " . $collection_id . " 
                    AND f.downloaded_timestamp >= '" . $filterDownloadToday . "'               
                    ";        
        $result = $this->_db->query($sql)->fetchAll();   
        
        $this->_db->commit();
        
        return $result[0]['cnt'];
    }  
    
    public function fetchCountDownloadsTodayForProjectNew($collection_id)
    {
        if(empty($collection_id)) {
            return 0;
        }
        
        $today = (new DateTime())->modify('-1 day');
        $filterDownloadToday = $today->format("Y-m-d H:i:s");

        $this->_db->query("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED")->execute();

        $this->_db->beginTransaction();
        
        $sql = "    SELECT COUNT(1) AS cnt
                    FROM ppload.ppload_files_downloaded_unique f
                    WHERE f.collection_id = " . $collection_id . " 
                    AND f.downloaded_timestamp >= '" . $filterDownloadToday . "'               
                    ";        
        $result = $this->_db->query($sql)->fetchAll(); 
        
        $this->_db->commit();
        
        return $result[0]['cnt'];
    }
    
    
    public function fetchCountDownloadsForFileAllTime($collectionId, $file_id)
    {
        if(empty($file_id) || empty($collectionId)) {
            return 0;
        }
        
        $sql = "    SELECT count_dl AS cnt
                    FROM ppload.stat_ppload_files_downloaded f
                    WHERE f.collection_id = " . $collectionId . " 
                    AND f.file_id = " . $file_id . "
                   ";        
        $result = $this->_db->query($sql)->fetchAll();      
        return $result[0]['cnt'];
    }     
<commit_msg>PploadFiles unblocking select for download count<commit_after><?php

/**
 *  ocs-webserver
 *
 *  Copyright 2016 by pling GmbH.
 *
 *    This file is part of ocs-webserver.
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Affero General Public License as
 *    published by the Free Software Foundation, either version 3 of the
 *    License, or (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Affero General Public License for more details.
 *
 *    You should have received a copy of the GNU Affero General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **/
class Default_Model_DbTable_PploadFiles extends Local_Model_Table
{
    /** @var  Zend_Cache_Core */
    protected $cache;
    
    protected $_name = "ppload.ppload_files";

    protected $_keyColumnsForRow = array('id');

    protected $_key = 'id';

    


    /**
     * @inheritDoc
     */
    public function init()
    {
        parent::init(); // TODO: Change the autogenerated stub
        $this->cache = Zend_Registry::get('cache');
    }
    
    
    /**
     * @param int $projectId Description   
     * @return array
     */
    public function fetchFilesForProject($collection_id)
    {

        if(empty($collection_id)) {
            return null;
        }
        
        $sql = " select f.*, pf.id as ppload_file_preview_id, pf.url_preview, pf.url_thumb 
                     from ppload.ppload_files f 
                     LEFT JOIN ppload.ppload_file_preview pf ON pf.collection_id = f.collection_id AND pf.file_id = f.id
                     where f.collection_id = :collection_id     
                     order by f.created_timestamp desc               
                   ";        
        /*
        $sql = " select * 
                     ,
                     (select tag.tag_fullname from tag_object, tag where tag_type_id = 3 and tag_group_id = 8 and tag_object.tag_id = tag.tag_id and tag_object.is_deleted = 0
                     and tag_object_id = f.id ) packagename
                    ,
                    (select tag.tag_fullname from tag_object, tag where tag_type_id = 3 and tag_group_id = 9 and tag_object.tag_id = tag.tag_id and tag_object.is_deleted = 0
                    and tag_object_id = f.id ) archname

                     from ppload.ppload_files f 
                     where f.collection_id = :collection_id     
                     order by f.created_timestamp desc               
                   ";        
         * 
         */
        $result = $this->_db->query($sql,array('collection_id' => $collection_id))->fetchAll();      
        return $result;
    }        

    public function fetchFilesCntForProject($collection_id)
    {

        if(empty($collection_id)) {
            return 0;
        }
        
        $sql = " select  count(1) as cnt
                     from ppload.ppload_files f 
                     where f.collection_id = :collection_id and f.active = 1                  
                   ";        
        $result = $this->_db->query($sql,array('collection_id' => $collection_id))->fetchAll();      
        return $result[0]['cnt'];
    }     
    
    
    public function fetchCountDownloadsTodayForProject($collection_id)
    {
        if(empty($collection_id)) {
            return 0;
        }
        
        $today = (new DateTime())->modify('-1 day');
        $filterDownloadToday = $today->format("Y-m-d H:i:s");

        $this->_db->query("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED")->execute();

        $this->_db->beginTransaction();
        
        $sql = "    SELECT COUNT(1) AS cnt
                    FROM ppload.ppload_files_downloaded f
                    WHERE f.collection_id = " . $collection_id . " 
                    AND f.downloaded_timestamp >= '" . $filterDownloadToday . "'               
                    ";        
        $result = $this->_db->query($sql)->fetchAll();   
        
        $this->_db->commit();
        
        return $result[0]['cnt'];
    }  
    
    public function fetchCountDownloadsTodayForProjectNew($collection_id)
    {
        if(empty($collection_id)) {
            return 0;
        }
        
        $today = (new DateTime())->modify('-1 day');
        $filterDownloadToday = $today->format("Y-m-d H:i:s");

        $this->_db->query("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED")->execute();

        $this->_db->beginTransaction();
        
        $sql = "    SELECT COUNT(1) AS cnt
                    FROM ppload.ppload_files_downloaded_unique f
                    WHERE f.collection_id = " . $collection_id . " 
                    AND f.downloaded_timestamp >= '" . $filterDownloadToday . "'               
                    ";        
        $result = $this->_db->query($sql)->fetchAll(); 
        
        $this->_db->commit();
        
        return $result[0]['cnt'];
    }
    
    
    public function fetchCountDownloadsForFileAllTime($collectionId, $file_id)
    {
        if(empty($file_id) || empty($collectionId)) {
            return 0;
        }
        
        $sql = "    SELECT count_dl AS cnt
                    FROM ppload.stat_ppload_files_downloaded f
                    WHERE f.collection_id = " . $collectionId . " 
                    AND f.file_id = " . $file_id . "
                   ";        
        $result = $this->_db->query($sql)->fetchAll();      
        return $result[0]['cnt'];
    }     

{'fraction_non_alphanumeric': 0.10333011158949126, 'fraction_numerical': 0.004393287057376329, 'mean_word_length': 1.6195627157652475, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 25, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1215144', 'n_tokens_mistral': 3290, 'n_tokens_neox': 3102, 'n_words': 750}