Files
fdn2/private/bin/importOldData.php
T
Riccardo Di Dato 1b0a3912d1 Corretta importazione dati per account antonio
Diminuita frequenza di aggiornamento del meteo
Inserito check per il meteo in caso di richiesta fallita
Inserito status accepted automatico sulla creazione di notizie in caso
di amministratori
Corretto social share in caso di dati open graph
2016-03-22 17:46:26 +01:00

141 lines
4.6 KiB
PHP

#!/usr/bin/php
<?php
/*
Author: Riccardo Di Dato
Creation Date: 04/mar/2016
*/
require_once(dirname(__FILE__)."/../load.php");
$pdo = new PDO("mysql:host=localhost;dbname=fdn_old","root","root",array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") );
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$admin = GlobalVariables::get("dao")->getFirst("AdminModel",array("username"=>"antonio.pianelli"));
if (is_null($admin)){
$statement = $pdo->query("select * from admin where id = 2;");
$data = reset($statement->fetchALL(PDO::FETCH_CLASS,"stdClass"));
$admin = new stdClass();
$admin->username = $data->username;
$admin->password = $data->password;
$admin->nome = $data->nome;
$admin->cognome = $data->cognome;
$admin->roles = 1022;
$admin->active = true;
$admin->activationSent = true;
$admin->email = "info@ifattidinapoli.it";
$admin = new AdminModel($admin);
GlobalVariables::get("dao")->save($admin);
}
else {
$admin->email = "info@ifattidinapoli.it";
GlobalVariables::get("dao")->save($admin);
}
$count = 0;
$imgDir = "/home/r.didato/mediaimg/notizie";
$statement = $pdo->query("select * from notizia order by id desc limit $count,100");
$dati = $statement->fetchALL(PDO::FETCH_CLASS,"stdClass");
while (is_array($dati) && sizeof($dati)>0){
foreach ($dati as $ele){
$notizia = new stdClass();
$notizia->status = NotiziaModel::STATUS_ACCEPTED;
$notizia->about = new stdClass();
$notizia->about->owner = $admin->id;
$notizia->about->author = $admin->nome." ".$admin->cognome;
$notizia->isAnsa = $ele->primaPagina==1;
$notizia->about->data = new MongoDate(strtotime($ele->data));
$notizia->titolo = $ele->mainTitle;
$notizia->sottotitolo = $ele->secTitle;
$corpo = $ele->corpo;
$corpo = preg_replace("~link[(]([^,]+),([^)]+)[)];~", '<a href="$2" target="_blank">$1</a>', $corpo);
$corpo = preg_replace("~mail[(]([^,]+),([^)]+)[)];~", '<a href="mailto:$2" target="_blank">$1</a>', $corpo);
$notizia->testo = $corpo;
switch ($ele->menu){
case 1://POLITICA
$notizia->category = NotiziaModel::CATEGORY_POLITICA;
break;
case 2://CRONACA
$notizia->category = NotiziaModel::CATEGORY_CRONACA;
break;
case 3://SPORT
$notizia->category = NotiziaModel::CATEGORY_SPORT;
break;
case 4://CULTURA
$notizia->category = NotiziaModel::CATEGORY_CULTURA;
break;
case 5://SPETTACOLO
$notizia->category = NotiziaModel::CATEGORY_CULTURA;
break;
case 4://FISCO E LAVORO
$notizia->category = NotiziaModel::CATEGORY_FISCOELAVORO;
break;
}
$notizia = new NotiziaModel($notizia);
GlobalVariables::get("dao")->save($notizia);
if (preg_match("/^http/",$ele->img)){
$media = new stdClass();
$media->mediaType = MediaModel::TYPE_YOUTUBE;
$matches = array();
if ( preg_match("~^http[s]?[:]//youtu\.be/(.+)$~", trim($ele->img), $matches) ){
$media->link = $matches[1];
}
else if (preg_match("~http[s]?[:]//www\.youtube\.com/embed/([^\"]++)~", trim($ele->img), $matches)){
$media->link = $matches[1];
}
else if (preg_match("~http[s]?[:]//www\.youtube\.com/watch[?]v[=](.+)$~", trim($ele->img), $matches)){
$media->link = $matches[1];
}
// LEGACY FORMAT http://www.youtube.com/v/c0B1snrcoPk&amp;hl=it_IT&amp;fs=1&amp;
else if (preg_match("~http[:]//www\.youtube\.com/v/([^&]++)~", trim($ele->img), $matches)){
$media->link = $matches[1];
}
// $media->link = $ele->img;
$media = new MediaModel($media);
GlobalVariables::get("dao")->save($media);
DaoMediaHandler::addMedia($notizia, $media);
}
$curDir = $imgDir."/".$ele->id;
if (is_dir($curDir) && is_dir($curDir."/big")){
$i=0;
$continue = true;
$curFile = $curDir."/big/".$i++.".jpg";
while(file_exists($curFile)){
$media = new stdClass();
$media->mediaType = MediaModel::TYPE_IMAGE;
$media = DaoMediaHandler::createNewFileBasedMedia($media, $curFile, "jpg");
DaoMediaHandler::addMedia($notizia, $media);
$curFile = $curDir."/big/".$i++.".jpg";
}
}
// $statement = $pdo->query("select * from commenti where notizia = ".$ele->id);
// $commenti = $statement->fetchALL(PDO::FETCH_CLASS,"stdClass");
// if (sizeof($commenti)>0){
// foreach ($commenti as $commento){
// $comm = new stdClass();
// $comm->notizia = $notizia->id;
// $comm->status = CommentoModel::STATUS_ACCEPTED;
// $comm->date = new MongoDate(strtotime($commento->data));
// $comm->titolo = $commento->titolo;
// $comm->testo = $commento->testo;
// }
// }
}
$count+=100;
$statement = $pdo->query("select * from notizia order by id desc limit $count,100");
$dati = $statement->fetchALL(PDO::FETCH_CLASS,"stdClass");
}
?>