Completed
Push — master ( 04d19a...743d3f )
by Simon
02:19
created

ClearOldData.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
if (isset($_SERVER['REQUEST_METHOD'])) {
3
	die();
4
} // Web clients die.
5
6
ini_set('display_errors', 1);
7
8
require_once 'config.inc.php';
9
require_once 'includes/PdoDatabase.php';
10
11
$db = gGetDb( );
12
13
$db->transactionally(function() use ($db)
14
{
15
	global $cDataClearIp, $cDataClearEmail, $dataclear_interval;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
16
    
17
	$query = $db->prepare("UPDATE request SET ip = :ip, forwardedip = null, email = :mail, useragent = '' WHERE date < DATE_SUB(curdate(), INTERVAL $dataclear_interval);");
18
	$success = $query->execute(array( 
19
		":ip" => $cDataClearIp,
20
		":mail" => $cDataClearEmail
21
	));
22
	
23
	if (!$success) {
24
		throw new TransactionException("Error in transaction: Could not clear data.");
25
	}
26
});
27
28
echo "Deletion complete.";
29