Rework nuove librerie mongo

Signed-off-by: Riccardo Di Dato <r.didato@asdynamics.it>
This commit is contained in:
Riccardo Di Dato
2017-08-17 14:58:02 +02:00
parent 542e94fd4d
commit ec7ebe7974
44 changed files with 403 additions and 238 deletions
+2 -1
View File
@@ -46,7 +46,8 @@ while (is_array($dati) && sizeof($dati)>0){
$notizia->about->author = $admin->nome." ".$admin->cognome;
$notizia->isAnsa = $ele->primaPagina==1;
$notizia->about->data = new MongoDate(strtotime($ele->data));
// $notizia->about->data = new MongoDate(strtotime($ele->data));
$notizia->about->data = new MongoDB\BSON\UTCDateTime(strtotime($ele->data)*1000) ; //New version
$notizia->titolo = $ele->mainTitle;
$notizia->sottotitolo = $ele->secTitle;
+3 -1
View File
@@ -12,9 +12,11 @@ Creation Date: 19/nov/2013
// $dbconn->location = "localhost";
// $dbconn->username = "root";
// $dbconn->password = "root";
// Password mongo produzione: p14n3ll1FDN2
$database = new stdClass();
$database->dbName = "fdn2";
$database->connectionString = null;
$database->connectionString = "mongodb://fdn2:p14n3ll1FDN2@db.ifattidinapoli.it/fdn2";
$currentSystem = new stdClass();
$currentSystem->storageBaseDir = "/home/asdynamics/storage"; // Il path con storage ecc in cui mettere immagini, file temporanei ecc
+16 -8
View File
@@ -127,10 +127,13 @@ class AnalyticsHelper {
public static function countNotiziaImpressions($id, $start = null, $end = null){
$searchArray = array("statType"=>StatisticModel::STAT_TYPE_NOTIZIA,"content.notizia"=>$id);
if (!is_null($start)){
$searchArray["date"]['$gte'] = new MongoDate($start);
// $searchArray["date"]['$gte'] = new MongoDate($start);
$searchArray["date"]['$gte'] = new MongoDB\BSON\UTCDateTime( $start * 1000 );
}
if (!is_null($end)){
$searchArray["date"]['$lte'] = new MongoDate($end);
// $searchArray["date"]['$lte'] = new MongoDate($end);
$searchArray["date"]['$lte'] = new MongoDB\BSON\UTCDateTime( $end * 1000 );
}
return GlobalVariables::get("dao")->count("StatisticModel",$searchArray);
}
@@ -204,10 +207,12 @@ class AnalyticsHelper {
public static function countBannerImpressions($id, $start = null, $end = null){
$searchArray = array("statType"=>StatisticModel::STAT_TYPE_BANNER_IMPRESSION,"content.banner"=>$id);
if (!is_null($start)){
$searchArray["date"]['$gte'] = new MongoDate($start);
// $searchArray["date"]['$gte'] = new MongoDate($start);
$searchArray["date"]['$gte'] = new MongoDB\BSON\UTCDateTime($start * 1000);
}
if (!is_null($end)){
$searchArray["date"]['$lte'] = new MongoDate($end);
// $searchArray["date"]['$lte'] = new MongoDate($end);
$searchArray["date"]['$lte'] = new MongoDB\BSON\UTCDateTime($end * 1000);
}
return GlobalVariables::get("dao")->count("StatisticModel",$searchArray);
}
@@ -267,10 +272,12 @@ class AnalyticsHelper {
public static function countBannerClicks($id, $start = null, $end = null){
$searchArray = array("statType"=>StatisticModel::STAT_TYPE_BANNER_CLICK,"content.banner"=>$id);
if (!is_null($start)){
$searchArray["date"]['$gte'] = new MongoDate($start);
// $searchArray["date"]['$gte'] = new MongoDate($start);
$searchArray["date"]['$gte'] = new MongoDB\BSON\UTCDateTime($start * 1000);
}
if (!is_null($end)){
$searchArray["date"]['$lte'] = new MongoDate($end);
// $searchArray["date"]['$lte'] = new MongoDate($end);
$searchArray["date"]['$lte'] = new MongoDB\BSON\UTCDateTime($end * 1000);
}
return GlobalVariables::get("dao")->count("StatisticModel",$searchArray);
}
@@ -306,11 +313,12 @@ class AnalyticsHelper {
}
}
$baseSearchArray = array("position"=>$position,"end"=>array('$gte'=>new MongoDate(strtotime("tomorrow"))),"categories"=>$category);
// $baseSearchArray = array("position"=>$position,"end"=>array('$gte'=>new MongoDate(strtotime("tomorrow"))),"categories"=>$category);
$baseSearchArray = array("position"=>$position,"end"=>array('$gte'=>new MongoDB\BSON\UTCDateTime( strtotime("tomorrow") * 1000 ) ),"categories"=>$category);
// Prendi il primo dei "mai mostrati oggi" tra quelli non presenti nella pagina
$todayPlusShown = array_merge($idList,$shown);
if (sizeof($todayPlusShown)>0){
$tmp = array_map(function ($id) {return new MongoId($id);}, $todayPlusShown);
$tmp = array_map(function ($id) {return new MongoDB\BSON\ObjectID($id);}, $todayPlusShown);
$tmp = array('_id'=>array('$nin'=>$tmp));
$rval = GlobalVariables::get("dao")->getFirst("BannerModel", array_merge($baseSearchArray, $tmp) );
}
+12 -6
View File
@@ -12,7 +12,8 @@ class PipelineHelper {
'$match'=>array(
'statType'=>StatisticModel::STAT_TYPE_PAGE,
'date'=>array(
'$gte'=>new MongoDate($startDate)
// '$gte'=>new MongoDate($startDate)
'$gte'=>new MongoDB\BSON\UTCDateTime($startDate * 1000)
)
)
),
@@ -84,8 +85,10 @@ class PipelineHelper {
'$match'=>array(
'statType'=>StatisticModel::STAT_TYPE_PAGE,
'tdate'=>array(
'$gte'=>new MongoDate($startDate),
'$lte'=>new MongoDate($endDate)
// '$gte'=>new MongoDate($startDate),
// '$lte'=>new MongoDate($endDate)
'$gte'=>new MongoDB\BSON\UTCDateTime($startDate * 1000),
'$lte'=>new MongoDB\BSON\UTCDateTime($endDate * 1000)
)
)
),
@@ -146,7 +149,8 @@ class PipelineHelper {
'$match'=>array(
'statType'=>StatisticModel::STAT_TYPE_PAGE,
'date'=>array(
'$gte'=>new MongoDate($startDate)
// '$gte'=>new MongoDate($startDate)
'$gte'=>new MongoDB\BSON\UTCDateTime($startDate * 1000)
)
)
),
@@ -212,7 +216,8 @@ class PipelineHelper {
'$match'=>array(
'statType'=>StatisticModel::STAT_TYPE_BANNER_IMPRESSION,
'content.position'=>$position,
'date'=>array( '$gte'=>new MongoDate(strtotime("today")) )
// 'date'=>array( '$gte'=>new MongoDate(strtotime("today")) )
'date'=>array( '$gte'=>new MongoDB\BSON\UTCDateTime(strtotime("today") * 1000) )
)
),
array(
@@ -246,7 +251,8 @@ class PipelineHelper {
'$match'=>array(
'statType'=>StatisticModel::STAT_TYPE_NOTIZIA,
'date'=>array(
'$gte'=>new MongoDate($startDate)
// '$gte'=>new MongoDate($startDate)
'$gte'=>new MongoDB\BSON\UTCDateTime($startDate * 1000)
)
)
),
+1 -1
View File
@@ -60,7 +60,7 @@ class RSSHelper {
}
}
echo '<pubDate>'.date(DATE_RFC2822,$notizia->about->data->sec).'</pubDate>',PHP_EOL;
echo '<pubDate>'.date(DATE_RFC2822,$notizia->about->data->toDateTime()->getTimestamp()).'</pubDate>',PHP_EOL;
echo '<guid>'.GUIHandler::getBaseUrl().'articolo_'.$notizia->id.'</guid>',PHP_EOL;
echo '</item>',PHP_EOL;
@@ -4,8 +4,8 @@ Author: Riccardo Di Dato
Creation Date: 23/dic/2015
*/
abstract class DaoSaveableDefaultImplementation implements DaoSaveable {
private $saveableObject;
abstract class DaoSaveableDefaultImplementation implements DaoSaveable, Serializable {
protected $saveableObject;
public function __construct($saveableObject = null){
@@ -20,8 +20,8 @@ abstract class DaoSaveableDefaultImplementation implements DaoSaveable {
if (strcmp($attr,"id")==0){
$attr = "_id";
}
if (!($value instanceof MongoId)){
$value = new MongoId($value);
if (!($value instanceof MongoDB\BSON\ObjectID)){
$value = new MongoDB\BSON\ObjectID($value);
}
}
$this->saveableObject->$attr = $value;
@@ -29,21 +29,15 @@ abstract class DaoSaveableDefaultImplementation implements DaoSaveable {
public function &__get($attr){
$rval = null;
if (strcmp($attr,"id")==0 || strcmp($attr,"_id")==0){
if (strcmp($attr,"id")==0){
$attr = "_id";
}
if ($this->hasProperty($attr)){
$idf = '$id';
$rval = &$this->saveableObject->$attr->$idf;
}
else {
$rval = null;
}
if (strcmp($attr,"id")==0){
$attr = '_id';
}
else {
if ($this->hasProperty($attr)){
$rval = &$this->saveableObject->$attr;
}
if (strcmp($attr,"_id")==0){
$rval = strval($rval);
}
return $rval;
}
@@ -71,7 +65,8 @@ abstract class DaoSaveableDefaultImplementation implements DaoSaveable {
private function toArray($input){
$rval = $input;
if (is_object($rval) ){
if (!($rval instanceof MongoId) && !($rval instanceof MongoDate) ){
// if (!($rval instanceof MongoId) && !($rval instanceof MongoDate) ){
if (!($rval instanceof MongoDB\BSON\ObjectID) && !($rval instanceof MongoDB\BSON\UTCDateTime) ){
$rval = (array)$input;
}
// $rval = (array)$input;
@@ -118,7 +113,8 @@ abstract class DaoSaveableDefaultImplementation implements DaoSaveable {
}
}
else if (is_object($rval)) {
if (!($rval instanceof MongoId) && !($rval instanceof MongoDate)){
// if (!($rval instanceof MongoId) && !($rval instanceof MongoDate)){
if (!($rval instanceof MongoDB\BSON\ObjectID) && !($rval instanceof MongoDB\BSON\UTCDateTime) ){
foreach ( $rval as $key=>$val){
$rval->$key = $this->toObject($val);
}
@@ -127,6 +123,58 @@ abstract class DaoSaveableDefaultImplementation implements DaoSaveable {
return $rval;
}
private function toArrayAndScalars($obj){
$rval = $obj;
if ( ( $rval instanceof MongoDB\BSON\ObjectID ) || ( $rval instanceof MongoDB\BSON\UTCDateTime ) ){
$rval = [
'__fetch' => get_class($rval),
'value' => strval($rval)
];
}
else if ( is_object( $rval ) ){
$rval = (array)($rval);
}
if ( is_array($rval) ) {
foreach ( $rval as $key=>$val ) {
if (!is_scalar($val)){
$rval[$key] = $this->toArrayAndScalars($val);
}
}
}
return $rval;
}
private function fromArrayAndScalars($obj){
$rval = $obj;
if (is_array($obj)){
if (array_key_exists("__fetch", $rval) && array_key_exists("value", $rval) ){
$class = $rval["__fetch"];
$val = $rval["value"];
$rval = new $class($val);
}
else {
foreach ($rval as $key=>$value){
$rval[$key] = $this->fromArrayAndScalars($value);
}
}
}
return $rval;
}
public function serialize(){
return json_encode( $this->toArrayAndScalars( $this->saveableObject ) );
}
public function unserialize($serialized){
$this->updateFromSaveableObj( $this->fromArrayAndScalars( json_decode( $serialized, true ) ) );
}
}
?>
+91 -58
View File
@@ -5,10 +5,20 @@ Creation Date: 22/dic/2015
*/
class GenericDao{
private $mongoObj;
private $database;
/**
* Nome del database
* @var string
*/
private $dbName;
/**
* Contiene il controller del driver mongo
* @var MongoDB\Driver\Manager
*/
private $client;
/**
* La connection string viene passata interamente a MongoClient, richiede formato 'mongo://server:port'.
* host1 e database sono obbligatori
@@ -17,17 +27,13 @@ class GenericDao{
*/
public function __construct($dbName, $connectionString = null){
if (is_null($connectionString)){
$this->mongoObj = new MongoClient();
$this->client = new MongoDB\Driver\Manager();
}
else {
// if (!preg_match("~^mongo[:][/][/]\w+[:].+$~",$connectionString)){
// throw new CoreException("Invalid connectionString parameter passed to 'GenericDao::__construct()' ('".print_r($connectionString,true)."')");
// }
$this->mongoObj = new MongoClient($connectionString);
$this->client = new MongoDB\Driver\Manager($connectionString);
}
$this->dbName = $dbName;
$this->database = $this->mongoObj->$dbName;
}
/**
@@ -48,6 +54,7 @@ class GenericDao{
* @return DaoSaveable[]
*/
public function query($modelClass, array $filter = array(), array $options = array()){
$modelClass = trim($modelClass);
if (!is_null($modelClass)){
if (!is_subclass_of($modelClass, "DaoSaveable", true)){
throw new CoreException("Invalid return class passed to GenericDao::query ($modelClass)");
@@ -55,7 +62,6 @@ class GenericDao{
}
$collectionName = $modelClass::getCollectionName();
$collection = $this->database->$collectionName;
$useFilter = $filter;
@@ -69,20 +75,23 @@ class GenericDao{
}
if (array_key_exists("_id",$useFilter) && is_string($useFilter["_id"])){
$useFilter["_id"] = new MongoId($useFilter["_id"]);
$useFilter["_id"] = new MongoDB\BSON\ObjectID($useFilter["_id"]);
}
$cursor = $collection->find($useFilter);
if (array_key_exists("sort",$options)){
$cursor->sort($options["sort"]);
}
if (array_key_exists("skip",$options)){
$cursor->skip($options["skip"]);
if (array_key_exists("creationDate",$options["sort"]) && !array_key_exists("_id",$options["sort"])){
$options["sort"]["_id"] = $options["sort"]["creationDate"];
}
}
if (array_key_exists("limit",$options)){
$cursor->limit($options["limit"]);
$options["limit"] = intval($options["limit"]);
}
if (array_key_exists("skip",$options)){
$options["skip"] = intval($options["skip"]);
}
$query = new MongoDB\Driver\Query($useFilter, $options);
$cursor = $this->client->executeQuery($this->dbName.".$collectionName",$query);
$rval = array();
foreach ($cursor as $element){
@@ -90,6 +99,7 @@ class GenericDao{
}
return $rval;
}
@@ -101,7 +111,6 @@ class GenericDao{
}
$collectionName = $modelClass::getCollectionName();
$collection = $this->database->$collectionName;
$useFilter = $filter;
@@ -115,13 +124,15 @@ class GenericDao{
}
if (array_key_exists("_id",$useFilter) && is_string($useFilter["_id"])){
$useFilter["_id"] = new MongoId($useFilter["_id"]);
$useFilter["_id"] = new MongoDB\BSON\ObjectID($useFilter["_id"]);
}
$command = new \MongoDB\Driver\Command( [ 'count' => $collectionName, 'query' => $useFilter ] );
$cursor = $this->client->executeCommand( $this->dbName, $command );
$cursor = $collection->find($useFilter);
return $cursor->count(true);
foreach ($cursor as $ele){
return $ele->n;
}
}
/**
@@ -132,13 +143,13 @@ class GenericDao{
* @return DaoSaveable
*/
public function getFirst($modelClass, array $filter = array(), array $options = array()){
$rval = $this->query($modelClass,$filter,$options);
if (sizeof($rval)>0){
$rval = reset($rval);
}
else {
$rval = null;
$options["limit"] = 1;
$rval = null;
$list = $this->query($modelClass, $filter, $options);
if (sizeof($list)>0){
$rval = reset($list);
}
return $rval;
}
@@ -148,18 +159,23 @@ class GenericDao{
*/
public function save(DaoSaveable $model){
$collectionName = $model->getCollectionName();
$collection = $this->database->$collectionName;
$saveObj = $model->getSaveableObj();
$bulk = new MongoDB\Driver\BulkWrite();
if ( array_key_exists("_id", $saveObj) && !is_null($saveObj["_id"]) ){
$collection->update( array("_id"=>$saveObj["_id"] ), $saveObj );
$bulk->update(array("_id"=>$saveObj["_id"] ),$saveObj);
}
else {
$saveObj["_id"] = new MongoId();
$collection->insert($saveObj);
$saveObj["_id"] = new MongoDB\BSON\ObjectID();
$bulk->insert($saveObj);
$model->updateFromSaveableObj($saveObj);
}
$writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 100);
$result = $this->client->executeBulkWrite($this->dbName.".$collectionName", $bulk, $writeConcern);
//TODO: (Rik) Controllo sul write concern
}
/**
@@ -167,16 +183,8 @@ class GenericDao{
* @param DaoSaveable $model
*/
public function delete(DaoSaveable $model){
$collectionName = $model->getCollectionName();
$collection = $this->database->$collectionName;
$saveObj = $model->getSaveableObj();
if ( array_key_exists("_id", $saveObj) && !is_null($saveObj["_id"]) ){
$saveObj["deleted"] = true;
$collection->update( array("_id"=>$saveObj["_id"] ), $saveObj );
$model->updateFromSaveableObj($saveObj);
}
$model->deleted = true;
$this->save($model);
}
@@ -190,15 +198,15 @@ class GenericDao{
* @return DaoSaveable[]
*/
public function aggregate($modelClass, array $pipeline = array(), array $options = array()){
$modelClass = trim($modelClass);
if (!is_null($modelClass)){
if (!is_subclass_of($modelClass, "DaoSaveable", true)){
throw new CoreException("Invalid return class passed to GenericDao::aggregate ($modelClass)");
}
}
$collectionName = $modelClass::getCollectionName();
$collection = $this->database->$collectionName;
$addDeleteMatch = true;
if (sizeof($pipeline)>0){
foreach ($pipeline as $ele){
@@ -207,7 +215,7 @@ class GenericDao{
if (array_key_exists('$match', $ele) && array_key_exists("deleted", $ele['$match'])){
$addDeleteMatch = false;
}
if (array_key_exists('$groupBy', $ele)){
// Sostituzione di id con _id
foreach ($ele as $key=>$val){
@@ -216,13 +224,13 @@ class GenericDao{
unset($val["id"]);
}
}
// Sostituzione di _id stringa con MongoId
if (array_key_exists("_id",$val) && is_string($val["_id"])){
$val["_id"] = new MongoId($val["_id"]);
$val["_id"] = new MongoDB\BSON\ObjectID( $val["_id"] );
}
}
}
}
}
@@ -230,23 +238,48 @@ class GenericDao{
if ($addDeleteMatch){
if (array_key_exists('$match', $pipeline[0])){
$pipeline[0]['$match']["deleted"] = false;
// array_unshift($pipeline[0]['$match'], array("deleted"=>false));
// array_unshift($pipeline[0]['$match'], array("deleted"=>false));
}
else {
array_unshift($pipeline, array('$match'=>array("deleted"=>false)));
}
}
$rval = array();
$command = new \MongoDB\Driver\Command( [ 'aggregate' => $collectionName, 'pipeline' => $pipeline ] );
$cursor = $this->client->executeCommand( $this->dbName, $command );
$resultArray = $collection->aggregate($pipeline);
if (array_key_exists("result", $resultArray)){
$rval = $resultArray["result"];
$rval = [];
foreach ($cursor as $ele){ // inganniamo il cursore, in realtà il risultato è uno
//TODO CHECK
if (!is_null($ele->result)){
$rval = $ele->result;
$rval = json_decode( json_encode($rval) ,true );
}
}
// var_dump($resultArray);
return $rval;
}
/**
* Ritorna la lista dei notizia model ordinati per pertinenza
* @param string $modelClass
* @param string $searchWord
* @param array $filter
* @param array $options
* @throws CoreException
* @return DaoSaveable[]
*/
public function search($modelClass, $search, array $filter = array(), array $options = array()){
$filter['$text'] = array('$search'=> trim($search) );
return $this->query($modelClass, $filter, $options);
}
public function searchCount($modelClass, $search, array $filter = array(), array $options = array()){
$filter['$text'] = array('$search'=> trim($search) );
return $this->count($modelClass, $filter, $options);
}
/**
* Ritorna la lista dei notizia model ordinati per pertinenza
@@ -257,7 +290,7 @@ class GenericDao{
* @throws CoreException
* @return DaoSaveable[]
*/
public function search($modelClass, $searchWord, array $filter = array(), array $options = array()){
public function searchOld($modelClass, $searchWord, array $filter = array(), array $options = array()){
if (!is_null($modelClass)){
if (!is_subclass_of($modelClass, "DaoSaveable", true)){
throw new CoreException("Invalid return class passed to GenericDao::query ($modelClass)");
@@ -310,8 +343,8 @@ class GenericDao{
}
public function searchCount($modelClass, $searchWord, array $filter = array(), array $options = array()){
if (!is_null($modelClass)){
public function searchCountOld($modelClass, $searchWord, array $filter = array(), array $options = array()){
if (!is_null($modelClass)){
if (!is_subclass_of($modelClass, "DaoSaveable", true)){
throw new CoreException("Invalid return class passed to GenericDao::query ($modelClass)");
}
@@ -13,7 +13,7 @@ class DaoMediaHandler implements MediaHandlerInterface{
$referenceIds = array();
if (sizeof($newsReference)>0){
foreach ($newsReference as $ref){
$referenceIds[] = new MongoId($ref);
$referenceIds[] = new MongoDB\BSON\ObjectID($ref);
}
}
$rval = array();
@@ -178,7 +178,7 @@ class DaoMediaHandler implements MediaHandlerInterface{
$mainMedia = $model->getMainMediaReference();
$tmp = null;
if(!is_null($mainMedia)){
$mainMediaId = new MongoId($mainMedia);
$mainMediaId = new MongoDB\BSON\ObjectID($mainMedia);
$tmp = GlobalVariables::get("dao")->getFirst("MediaModel",array("id"=>$mainMediaId));
}
// var_dump($tmp);
+2 -1
View File
@@ -13,7 +13,8 @@ class AccessModel extends Model {
$requiredProps = array("related");
if (!$this->hasProperty("date")){
$this->date = new MongoDate();
// $this->date = new MongoDate();
$this->date = new MongoDB\BSON\UTCDateTime( time() * 1000 );
}
foreach ($requiredProps as $prop){
+2 -1
View File
@@ -37,7 +37,8 @@ class CommentoModel extends Model{
}
if (!$this->hasProperty("date")){
$this->date = new MongoDate();
// $this->date = new MongoDate();
$this->date = new MongoDB\BSON\UTCDateTime( time() * 1000 );
}
}
+2 -1
View File
@@ -11,7 +11,8 @@ class LogModel extends Model {
parent::__construct($saveableObject);
if (!$this->hasProperty("date")){
$this->date = new MongoDate();
// $this->date = new MongoDate();
$this->date = new MongoDB\BSON\UTCDateTime( time() * 1000 );
}
}
+2 -1
View File
@@ -21,7 +21,8 @@ class MailTemplateModel extends Model{
}
if (!$this->hasProperty("date")){
$this->date = new MongoDate();
// $this->date = new MongoDate();
$this->date = new MongoDB\BSON\UTCDateTime( time() * 1000 );
}
foreach ($requiredProps as $prop){
@@ -22,7 +22,8 @@ class PasswordRecoveryRequestModel extends Model{
}
if (!$this->hasProperty("date")){
$this->date = new MongoDate();
// $this->date = new MongoDate();
$this->date = new MongoDB\BSON\UTCDateTime( time() * 1000 );
}
if (!$this->hasProperty("sent")){
+2 -1
View File
@@ -27,7 +27,8 @@ class StatisticModel extends Model {
$requiredProps = array("user","content","source", "ip", "statType");
if (!$this->hasProperty("date")){
$this->date = new MongoDate();
// $this->date = new MongoDate();
$this->date = new MongoDB\BSON\UTCDateTime( time() * 1000 );
}
foreach ($requiredProps as $prop){
+3 -2
View File
@@ -70,8 +70,9 @@ class DatatablesHelper {
$rval->$key = self::getObjectFromFieldsArray($obj->$key, $val);
}
else {
if ($obj->$key instanceof MongoDate){
$rval->$key = date("d-m-Y H:i",$obj->$key->sec);
if ($obj->$key instanceof MongoDB\BSON\UTCDateTime){
// $rval->$key = date("d-m-Y H:i",$obj->$key->sec);
$rval->$key = date("d-m-Y H:i", $obj->$key->toDateTime()->getTimestamp() );
}
else {
$rval->$key = $obj->$key;
+1 -1
View File
@@ -73,7 +73,7 @@ class CommentoBlock {
$rval.= '<div class="commentoTitolo">'.$this->commento->titolo.'</div>';
$rval.= '<div class="commentoTesto">'.$this->commento->testo.'</div>';
$rval.= '<div class="commentoUser">'.$userString.'</div>';
$rval.= '<div class="commentoDate">'.date("d-m-Y H:i",$this->commento->date->sec).'</div>';
$rval.= '<div class="commentoDate">'.date("d-m-Y H:i",$this->commento->date->toDateTime()->getTimestamp()).'</div>';
$rval.= "</div>";
return $rval;
+12 -4
View File
@@ -391,16 +391,24 @@ class GUIHandler {
// }
$stats = GlobalVariables::get("dao")->aggregate("StatisticModel",PipelineHelper::getMostViewedOfLastDays(strtotime("-7 days"),5));
$idArray = array_map(function ($ele){ return new MongoId($ele["_id"]["notizia"]);}, $stats);
$idArray = array_map(function ($ele){ return new MongoDB\BSON\ObjectID($ele["_id"]["notizia"]);}, $stats);
// $lastsNews = GlobalVariables::get("dao")->query("NotiziaModel",
// array("status"=>NotiziaModel::STATUS_ACCEPTED,"_id"=>array('$in'=>$idArray),"about.data"=>array('$lte'=>new MongoDate(),'$gte'=>new MongoDate(strtotime('-2 months')))),
// array("sort"=>array("about.data"=>-1))
// );
$lastsNews = GlobalVariables::get("dao")->query("NotiziaModel",
array("status"=>NotiziaModel::STATUS_ACCEPTED,"_id"=>array('$in'=>$idArray),"about.data"=>array('$lte'=>new MongoDate(),'$gte'=>new MongoDate(strtotime('-2 months')))),
array("status"=>NotiziaModel::STATUS_ACCEPTED,"_id"=>array('$in'=>$idArray),"about.data"=>array('$lte'=>new MongoDB\BSON\UTCDateTime( time() * 1000 ),'$gte'=>new MongoDB\BSON\UTCDateTime( strtotime('-2 months') * 1000 ) )),
array("sort"=>array("about.data"=>-1))
);
if (sizeof($lastsNews)<5){
$missing = 5-sizeof($lastsNews);
// $add = GlobalVariables::get("dao")->query("NotiziaModel",
// array("status"=>NotiziaModel::STATUS_ACCEPTED,"_id"=>array('$nin'=>$idArray),"about.data"=>array('$lte'=>new MongoDate())),
// array("sort"=>array("about.data"=>-1),"limit"=>$missing)
// );
$add = GlobalVariables::get("dao")->query("NotiziaModel",
array("status"=>NotiziaModel::STATUS_ACCEPTED,"_id"=>array('$nin'=>$idArray),"about.data"=>array('$lte'=>new MongoDate())),
array("status"=>NotiziaModel::STATUS_ACCEPTED,"_id"=>array('$nin'=>$idArray),"about.data"=>array( '$lte'=>new MongoDB\BSON\UTCDateTime( time() * 1000 ) ) ),
array("sort"=>array("about.data"=>-1),"limit"=>$missing)
);
$lastsNews = array_merge($lastsNews,$add);
@@ -429,7 +437,7 @@ class GUIHandler {
$i=0;
foreach($lastsNews as $last){
$i++;
$data = $mesi[date("n",$last->about->data->sec)]." ".date("Y",$last->about->data->sec);
$data = $mesi[date("n",$last->about->data->toDateTime()->getTimestamp())]." ".date("Y",$last->about->data->toDateTime()->getTimestamp());
$string = (strlen($last->titolo) > 103) ? substr($last->titolo,0,100).'...' : $last->titolo;?>
<a href="<?php echo $last->getAbsoluteUrl();?>" id="last_<?php echo $i;?>" class="lastContainer">
<div class="lastData"><?php echo $data;?></div>
+2 -2
View File
@@ -402,7 +402,7 @@ class GUIHandlerMobile {
public static function generateRightBannerBlock($category = BannerModel::GENERAL_CATEGORY){
$stats = GlobalVariables::get("dao")->aggregate("StatisticModel",PipelineHelper::getMostViewedOfLastDays(strtotime("-7 days"),5));
$idArray = array_map(function ($ele){ return new MongoId($ele["_id"]["notizia"]);}, $stats);
$idArray = array_map(function ($ele){ return new MongoDB\BSON\ObjectID($ele["_id"]["notizia"]);}, $stats);
$lastsNews = GlobalVariables::get("dao")->query("NotiziaModel",
array("status"=>NotiziaModel::STATUS_ACCEPTED,"_id"=>array('$in'=>$idArray)),
@@ -446,7 +446,7 @@ class GUIHandlerMobile {
$i=0;
foreach($lastsNews as $last){
$i++;
$data = $mesi[date("n",$last->about->data->sec)]." ".date("Y",$last->about->data->sec);
$data = $mesi[date("n",$last->about->data->toDateTime()->getTimestamp())]." ".date("Y",$last->about->data->toDateTime()->getTimestamp());
$string = (strlen($last->titolo) > 103) ? substr($last->titolo,0,100).'...' : $last->titolo;?>
<a href="articolo.php?id=<?php echo $last->id;?>" id="last_<?php echo $i;?>" class="lastContainer">
<div class="lastData"><?php echo $data;?></div>
@@ -22,7 +22,8 @@ abstract class LoginManager {
ASDSessionHandler::setSessionValue(static::getSessionVariableName(), $user);
$user->lastConnection = new stdClass();
$user->lastConnection->date = new MongoDate();
// $user->lastConnection->date = new MongoDate();
$user->lastConnection->date = new MongoDB\BSON\UTCDateTime(time()*1000);
$user->lastConnection->ip = $_SERVER['REMOTE_ADDR'];
$dao->save($user);
+16 -36
View File
@@ -17,57 +17,37 @@ require_once(dirname(__FILE__)."/FileLogger.php");
// |_____\___/ \__, |\__, |\___|_| |___/
// |___/ |___/
//
LoggingFacilityManager::addLogger(
"system",
new SyslogLogger("System",$systemCatalogManager,true)
);
$sysLog = new SyslogLogger("System",$systemCatalogManager,true);
LoggingFacilityManager::addLogger( "system", $sysLog );
LoggingFacilityManager::getLogger("system")->setLoggingLevel(LoggingFacility::$LEVEL_DEBUG);
LoggingFacilityManager::addLogger(
"core",
new FileLogger("Core",$systemCatalogManager,$config->files->core_log,true)
);
$coreLog = new FileLogger("Core",$systemCatalogManager,$config->files->core_log,true);
LoggingFacilityManager::addLogger( "core", $coreLog );
LoggingFacilityManager::getLogger("core")->setLoggingLevel(LoggingFacility::$LEVEL_DEBUG);
LoggingFacilityManager::addLogger(
"dao",
new FileLogger("DAO",$systemCatalogManager,$config->files->dao_log,true)
);
$daoLog = new FileLogger("DAO",$systemCatalogManager,$config->files->dao_log,true);
LoggingFacilityManager::addLogger( "dao",$daoLog );
LoggingFacilityManager::getLogger("dao")->setLoggingLevel(LoggingFacility::$LEVEL_DEBUG);
LoggingFacilityManager::addLogger(
"task",
new FileLogger("Task",$systemCatalogManager,$config->files->task_log,true)
);
$taskLog = new FileLogger("Task",$systemCatalogManager,$config->files->task_log,true);
LoggingFacilityManager::addLogger( "task", $taskLog );
LoggingFacilityManager::getLogger("task")->setLoggingLevel(LoggingFacility::$LEVEL_DEBUG);
LoggingFacilityManager::addLogger(
"general",
new FileLogger("General",$systemCatalogManager,$config->files->general_log,true)
);
$generalLog = new FileLogger("General",$systemCatalogManager,$config->files->general_log,true);
LoggingFacilityManager::addLogger( "general", $generalLog );
LoggingFacilityManager::getLogger("general")->setLoggingLevel(LoggingFacility::$LEVEL_DEBUG);
LoggingFacilityManager::addLogger(
"gui",
new FileLogger("GUI",$systemCatalogManager,$config->files->gui_log,true)
);
$guiLog = new FileLogger("GUI",$systemCatalogManager,$config->files->gui_log,true);
LoggingFacilityManager::addLogger( "gui", $guiLog );
LoggingFacilityManager::getLogger("gui")->setLoggingLevel(LoggingFacility::$LEVEL_DEBUG);
LoggingFacilityManager::addLogger(
"mail",
new FileLogger("Mail",$systemCatalogManager,$config->files->mail_log,true)
);
$mailLog = new FileLogger("Mail",$systemCatalogManager,$config->files->mail_log,true);
LoggingFacilityManager::addLogger( "mail", $mailLog );
LoggingFacilityManager::getLogger("mail")->setLoggingLevel(LoggingFacility::$LEVEL_DEBUG);
LoggingFacilityManager::addLogger(
"api",
new FileLogger("API",$systemCatalogManager,$config->files->api_log,true)
);
$apiLog = new FileLogger("API",$systemCatalogManager,$config->files->api_log,true);
LoggingFacilityManager::addLogger( "api", $apiLog );
LoggingFacilityManager::getLogger("api")->setLoggingLevel(LoggingFacility::$LEVEL_DEBUG);
?>
+2 -1
View File
@@ -56,7 +56,8 @@ class FDN_Mailer {
}
else {
$mail->status = MailModel::STATUS_SENT;
$mail->sendDate = new MongoDate();
// $mail->sendDate = new MongoDate();
$mail->sendDate = new MongoDB\BSON\UTCDateTime( time() * 1000 );
}
GlobalVariables::get("dao")->save($mail);
}
@@ -15,7 +15,8 @@ class DeleteOldPasswordResetRequestsTask extends Task {
}
public static function execute(){
$requests = GlobalVariables::get("dao")->query("PasswordRecoveryRequestModel",array("date"=>array( '$lte'=>new MongoDate( strtotime("-10 minutes") ) ) ) ,array("limit"=>10));
// $requests = GlobalVariables::get("dao")->query("PasswordRecoveryRequestModel",array("date"=>array( '$lte'=>new MongoDate( strtotime("-10 minutes") ) ) ) ,array("limit"=>10));
$requests = GlobalVariables::get("dao")->query("PasswordRecoveryRequestModel",array("date"=>array( '$lte'=>new MongoDB\BSON\UTCDateTime( strtotime("-10 minutes") * 1000 ) ) ) ,array("limit"=>10));
if(sizeof($requests)>0){
foreach ($requests as $request){
GlobalVariables::get("dao")->delete($request);
+2 -1
View File
@@ -14,7 +14,8 @@ class NewsletterCheckTask extends Task {
}
public static function execute(){
$mailTemplates = GlobalVariables::get("dao")->query("MailTemplateModel",array("status"=>MailTemplateModel::STATUS_READY,"date"=>array('$lte'=>new MongoDate())));
// $mailTemplates = GlobalVariables::get("dao")->query("MailTemplateModel",array("status"=>MailTemplateModel::STATUS_READY,"date"=>array('$lte'=>new MongoDate())));
$mailTemplates = GlobalVariables::get("dao")->query("MailTemplateModel",array("status"=>MailTemplateModel::STATUS_READY,"date"=>array('$lte'=>new MongoDB\BSON\UTCDateTime( time() * 1000 ))));
if (sizeof($mailTemplates)>0){
foreach ($mailTemplates as $mailTemplate){
FDN_Mailer::generateTemplateQueue($mailTemplate);