Files
fdn2/private/bin/importOldData.php
T

121 lines
3.8 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 = 1020;
$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);
}
$imgDir = "/home/rik/Scrivania/FDN_BAK/mediaimg/notizie";
$statement = $pdo->query("select * from notizia order by id desc limit 0,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;
$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;
// }
// }
}
// }
?>