Browse Source

Prende un file, crea un roll e inserisce le mail dei mambri nel database

root 7 years ago
parent
commit
eef27cac21
1 changed files with 60 additions and 0 deletions
  1. 60 0
      loader.php

+ 60 - 0
loader.php

@@ -0,0 +1,60 @@
+<?php
+include_once 'config/config.php';
+include_once "vendor/notorm/NotORM.php";
+
+//exit('Commentami, lanciami e ricommentami.');
+
+function getToken($length = 12){
+	return uniqId();
+	//PHP7
+	//return bin2hex(random_bytes($length));
+}
+
+$pdo = new PDO("mysql:host=".$db_host.";dbname=".$db_dbname,
+	$db_user,
+	$db_pass
+);
+
+function getMyDateFormatted($datestr){
+	$date = null;
+	if(empty($datestr)){
+		$date = new DateTime();
+	} else {
+		$date = new DateTime($datestr);
+	}
+	
+	return $date->format('Y-m-d');
+}
+
+
+
+$db = new NotORM($pdo);
+
+$db->debug = true;
+
+$today = getMyDateFormatted("");
+$last = getMyDateFormatted($rollday);
+
+//Inserisco la mailing list e ottengo l'id
+$ret = $db->roll()->insert(array(
+	"ml" => $ml,
+	"startroll" => $today, 
+	"endroll" => $last
+));
+
+$file = fopen($filename, "r");
+while(!feof($file)){
+    $line = fgets($file);
+	$sanitized_mail =  filter_var($line, FILTER_SANITIZE_EMAIL);
+	if($sanitized_mail !== "") {
+		$token = getToken();
+
+		//Inserisco le mail dei membri della mailing list	
+		$db->$db_table()->insert(array(
+			"id" => $ret['id'],
+			"token" => $token,
+			"email" => $sanitized_mail 
+		));
+	}
+}
+fclose($file);