Goteo /controller/cron/verify.php

Language PHP Lines 134
MD5 Hash 780c8f914caf2a7527fd40ec4c550da0
Repository https://github.com/alugo/Goteo.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/*
 *  Copyright (C) 2012 Platoniq y Fundación Fuentes Abiertas (see README for details)
 *	This file is part of Goteo.
 *
 *  Goteo 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.
 *
 *  Goteo 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 Goteo.  If not, see <http://www.gnu.org/licenses/agpl.txt>.
 *
 */

namespace Goteo\Controller\Cron {

    use Goteo\Model,
        Goteo\Core\Redirection,
        Goteo\Core\Error;

    class Verify {

        public static function process ($debug = false) {

            // eliminamos ACL innecesario
            $sql = "DELETE FROM `acl` 
                WHERE id > 1000 
                AND role_id = 'user' 
                AND user_id != '*' 
                AND (url LIKE '%project/edit%'  OR url LIKE '%project/delete%') 
                AND DATE_FORMAT(from_unixtime(unix_timestamp(now()) - unix_timestamp(`timestamp`)), '%j') > 30
                ";
            
            // echo $sql . '<br />';
            $query = Model\Project::query($sql);
            $count = $query->rowCount();
            if ($debug) echo "Eliminados $count registros de ACL antiguo.<br />";
            
            // eliminamos feed antiguo
            $sql1 = "DELETE 
                FROM `feed` 
                WHERE type != 'goteo' 
                AND DATE_FORMAT(from_unixtime(unix_timestamp(now()) - unix_timestamp(`datetime`)), '%j') > 30
                AND (url NOT LIKE '%updates%' OR url IS NULL)
                ";
            
            // echo $sql . '<br />';
            $query1 = Model\Project::query($sql1);
            $count1 = $query1->rowCount();
            if ($debug) echo "Eliminados $count1 registros de feed.<br />";
            
            // eliminamos mail antiguo
            $sql2 = "DELETE
                FROM `mail` 
                WHERE (template != 33 OR template IS NULL)
                AND DATE_FORMAT(from_unixtime(unix_timestamp(now()) - unix_timestamp(`date`)), '%j') > 30
                ";
            
            // echo $sql2 . '<br />';
            $query2 = Model\Project::query($sql2);
            $count2 = $query2->rowCount();
            if ($debug) echo "Eliminados $count2 registros de mail.<br />";
            
            // eliminamos registros de imágenes cuyo archivo no esté en el directorio de imágenes


            // busco aportes incompletos con codigo de autorización
            $sql5 = "SELECT * FROM invest WHERE status = -1 AND transaction IS NOT NULL";
            $query5 = Model\Project::query($sql5);
            foreach ($query5->fetchAll(\PDO::FETCH_OBJ) as $row) {
                @mail(\GOTEO_FAIL_MAIL,
                    'Aporte Incompleto con numero de autorización. En ' . SITE_URL,
                    'Aporte Incompleto con numero de autorización: <pre>' . print_r($row, 1). '</pre>');
            }
            
            
            // eliminamos aportes incompletos
            /*
            $sql4 = "DELETE
                FROM `invest` 
                WHERE status = -1
                AND DATE_FORMAT(from_unixtime(unix_timestamp(now()) - unix_timestamp(`datetime`)), '%j') > 120
                ";
            
            //echo $sql4 . '<br />';
            $query4 = Model\Project::query($sql4);
            $count4 = $query4->rowCount();
            // -- eliminamos registros relativos a aportes no existentes
            Model\Project::query("DELETE FROM `invest_address` WHERE invest NOT IN (SELECT id FROM `invest`)");
            Model\Project::query("DELETE FROM `invest_detail`  WHERE invest NOT IN (SELECT id FROM `invest`)");
            Model\Project::query("DELETE FROM `invest_reward`  WHERE invest NOT IN (SELECT id FROM `invest`)");
            echo "Eliminados $count4 aportes incompletos y sus registros (recompensa, dirección, detalles) relacionados.<br />";
            */
            
            if ($debug) echo "<hr /> Iniciamos caducidad de tokens<br/>";
            // eliminamos los tokens que tengan más de 4 días
            $sql5 = "SELECT id, token FROM user WHERE token IS NOT NULL AND token != '' AND token LIKE '%¬%'";
            $query5 = Model\Project::query($sql5);
            foreach ($query5->fetchAll(\PDO::FETCH_OBJ) as $row) {
                $parts = explode('¬', $row->token);
                $datepart = strtotime($parts[2]);
                $today = date('Y-m-d');
                $datedif = strtotime($today) - $datepart;
                $days = round($datedif / 86400);
                if ($days > 4 || !isset($parts[2])) {
                    if ($debug) echo "User: $row->id  ;  Token: $row->token  ;  Datepart: $parts[2]   =>  $datepart  ;  Compare: $today  =>  $datedif  ;  Days: $days  ;   ";
                    
                    if (Model\Project::query("UPDATE user SET token = '' WHERE id = ?", array($row->id))) {
                        if ($debug) echo "Token borrado.";
                    } else {
                        if ($debug) echo "Fallo al borrar Token!!!";
                    }
                    if ($debug) echo "<br />";
                }
                
            }
            
            if ($debug) echo "<br />";
                
            echo 'Verify Listo!';

            return;
        }

    }

}
Back to Top