18 Commits
Author SHA1 Message Date
r.didato 7bab6253cf Automation 2022-09-25 15:43:49 +02:00
r.didato f7db85cc13 Scripts 2022-09-25 15:38:34 +02:00
r.didato 09396f8c98 Stats 2022-09-25 13:55:59 +02:00
r.didato 064eeec5a0 #9 Still in testing 2022-09-23 01:33:08 +02:00
r.didato 47470fef2e Fix cache image 2022-09-20 00:53:06 +02:00
r.didato 4010c65dbc Typo 2022-09-19 23:54:57 +02:00
r.didato e2b8470e54 CICD 2022-09-19 23:01:35 +02:00
r.didato 3546e51d9e CICD 2022-09-19 23:00:10 +02:00
r.didato 7744dcabc1 CICD 2022-09-19 22:54:51 +02:00
r.didato 9e6cb3780e Fix build process 2022-09-19 22:52:10 +02:00
r.didato afb1bff624 comments 2022-09-19 22:48:41 +02:00
r.didato 70a0b64c04 cfg 2022-09-19 22:47:29 +02:00
r.didato c772a20bf9 CICD 2022-09-19 22:46:03 +02:00
r.didato 05987f26e9 CICD 2022-09-19 22:44:44 +02:00
r.didato 78f68a82a3 CICD 2022-09-19 22:43:29 +02:00
r.didato 55cb0b75b9 CICD 2022-09-19 22:30:03 +02:00
r.didato 5cf34f1aea compose 2022-09-19 22:26:01 +02:00
r.didato 28c70e03bf compose 2022-09-19 22:25:29 +02:00
17 changed files with 692 additions and 153 deletions
+1
View File
@@ -6,6 +6,7 @@
* File : convertStats.php
*******************************************/
die();
require_once(dirname(__FILE__)."/../load.php");
$iteration = 0;
+363
View File
@@ -0,0 +1,363 @@
#!/usr/local/bin/php
<?php
/******************************************
* Author : Riccardo Di Dato
* Created On : Tue Aug 30 2022
* File : convertStats.php
*******************************************/
require_once(dirname(__FILE__)."/../load.php");
function getDailyBannerImpressionsPipeline($startDate, $endDate) {
return [
[
'$project' => [
'tdate'=> [
'$add' => [ '$date' , 60*60*1000 ]
],
"statType" => '$statType',
'user' => '$user',
'banner' => '$content.banner',
]
],
[
'$match' => [
'statType' => StatisticModel::STAT_TYPE_BANNER_IMPRESSION,
'tdate' => [
'$gte'=>new MongoDB\BSON\UTCDateTime($startDate * 1000),
'$lte'=>new MongoDB\BSON\UTCDateTime($endDate * 1000)
]
]
],
[
'$group' => [
'_id' => [
'date' => [
'day' => [ '$dayOfMonth' => '$tdate' ],
"month" => [ '$month' => '$tdate' ],
"year" => [ '$year'=>'$tdate' ]
],
'banner' => '$banner',
],
"visualizzazioni" => [ '$sum' => 1 ]
]
]
];
}
function getDailyBannerClicksPipeline($startDate, $endDate) {
return [
[
'$project' => [
'tdate'=> [
'$add' => [ '$date' , 60*60*1000 ]
],
"statType" => '$statType',
'user' => '$user',
'banner' => '$content.banner',
]
],
[
'$match' => [
'statType' => StatisticModel::STAT_TYPE_BANNER_CLICK,
'tdate' => [
'$gte'=>new MongoDB\BSON\UTCDateTime($startDate * 1000),
'$lte'=>new MongoDB\BSON\UTCDateTime($endDate * 1000)
]
]
],
[
'$group' => [
'_id' => [
'date' => [
'day' => [ '$dayOfMonth' => '$tdate' ],
"month" => [ '$month' => '$tdate' ],
"year" => [ '$year'=>'$tdate' ]
],
'banner' => '$banner',
],
"visualizzazioni" => [ '$sum' => 1 ]
]
]
];
}
function getDailyNotiziaImpressionsPipeline($startDate, $endDate) {
return [
[
'$project' => [
'tdate'=> [
'$add' => [ '$date' , 60*60*1000 ]
],
"statType" => '$statType',
'user' => '$user',
"content" => '$content'
]
],
[
'$match' => [
'statType' => StatisticModel::STAT_TYPE_NOTIZIA,
'tdate' => [
'$gte'=>new MongoDB\BSON\UTCDateTime($startDate * 1000),
'$lte'=>new MongoDB\BSON\UTCDateTime($endDate * 1000)
]
]
],
[
'$group' => [
'_id' => [
'date' => [
'day' => [ '$dayOfMonth' => '$tdate' ],
"month" => [ '$month' => '$tdate' ],
"year" => [ '$year'=>'$tdate' ]
],
'notizia' => '$content.notizia',
],
"visualizzazioni" => [ '$sum' => 1 ]
]
]
];
}
function getYearlyNotiziaImpressionsPipeline($startDate, $endDate) {
return [
[
'$project' => [
'tdate'=> [
'$add' => [ '$date' , 60*60*1000 ]
],
"statType" => '$statType',
'user' => '$user',
"content" => '$content'
]
],
[
'$match' => [
'statType' => StatisticModel::STAT_TYPE_NOTIZIA,
'tdate' => [
'$gte'=>new MongoDB\BSON\UTCDateTime($startDate * 1000),
'$lte'=>new MongoDB\BSON\UTCDateTime($endDate * 1000)
]
]
],
[
'$group' => [
'_id' => [
'notizia' => '$content.notizia',
],
"visualizzazioni" => [ '$sum' => 1 ]
]
]
];
}
function getDailyPageImpressionsPipeline($startDate, $endDate) {
return [
[
'$project' => [
'tdate'=> [
'$add' => [ '$date' , 60*60*1000 ]
],
"statType" => '$statType',
'user' => '$user',
'content' => '$content',
]
],
[
'$match' => [
'statType' => StatisticModel::STAT_TYPE_PAGE,
'tdate' => [
'$gte'=>new MongoDB\BSON\UTCDateTime($startDate * 1000),
'$lte'=>new MongoDB\BSON\UTCDateTime($endDate * 1000)
]
]
],
[
'$group' => [
'_id' => [
'date' => [
'day' => [ '$dayOfMonth' => '$tdate' ],
"month" => [ '$month' => '$tdate' ],
"year" => [ '$year'=>'$tdate' ]
],
'user' => '$user.id',
'content' => '$content',
],
"visualizzazioni" => [ '$sum' => 1 ]
]
],
[
'$group' => [
'_id' => [
'date' => '$_id.date',
'content' => '$_id.content',
],
"visualizzazioni" => [ '$sum' => '$visualizzazioni' ],
'isNewToday' => [ '$sum' => 1 ],
'isAbsoluteNew' => [ '$sum' => 1 ]
]
]
];
}
function getMonthlyPageImpressionsPipeline($startDate, $endDate) {
return [
[
'$match' => [
'statType' => StatisticModel::STAT_TYPE_PAGE,
'tdate' => [
'$gte'=>new MongoDB\BSON\UTCDateTime($startDate * 1000),
'$lte'=>new MongoDB\BSON\UTCDateTime($endDate * 1000)
]
]
],
[
'$group' => [
'_id' => [
'date' => [
"month" => [ '$month' => '$tdate' ],
"year" => [ '$year'=>'$tdate' ]
],
'user' => '$user.id',
'content' => '$content',
]
]
],
[
'$group' => [
'_id' => [
'date' => '$_id.date',
'content' => '$_id.content',
],
"isMonthlyNew" => [ '$sum' => 1 ]
]
]
];
}
$curYear = intval(date("Y"));
for ($y = 2016; $y <= intval(date("Y")); $y++) {
echo "Working on year : $y", PHP_EOL;
$from = strtotime($y."-01-01");
$to = strtotime($y."-12-31");
$dao = GlobalVariables::get("dao");
if ($dao instanceof GenericDao) {
$pipe = getDailyPageImpressionsPipeline( $from, $to );
echo " - Working on Daily Page Impressions", PHP_EOL;
$data = $dao->aggregate(
StatisticModel::class,
$pipe,
['cursor' => true]
);
foreach ($data as $elem) {
AnalyticsHelper::multiPageImpression(
$elem->_id->content,
$elem->_id->date->day,
$elem->_id->date->month,
$elem->_id->date->year,
$elem->visualizzazioni,
$elem->isNewToday,
0,
$elem->isAbsoluteNew
);
}
$pipe = getMonthlyPageImpressionsPipeline( $from, $to );
echo " - Working on Monthly Page Impressions", PHP_EOL;
$data = $dao->aggregate(
StatisticModel::class,
$pipe,
['cursor' => true]
);
foreach ($data as $elem) {
AnalyticsHelper::multiPageImpression(
$elem->_id->content,
1,
$elem->_id->date->month,
$elem->_id->date->year,
0,
0,
$elem->isMonthlyNew,
0
);
}
if ($y == $curYear) {
$pipe = getDailyNotiziaImpressionsPipeline( $from, $to );
}
else {
$pipe = getYearlyNotiziaImpressionsPipeline($from, $to);
}
echo " - Working on Notizia Impressions", PHP_EOL;
$data = $dao->aggregate(
StatisticModel::class,
$pipe,
['cursor' => true]
);
foreach ($data as $elem) {
$day = $y == 2022 ? $elem->_id->date->day : 1;
$month = $y == 2022 ? $elem->_id->date->month : 1;
AnalyticsHelper::multiNotiziaImpression(
$elem->_id->notizia,
$day,
$month,
$y,
$elem->visualizzazioni
);
}
$pipe = getDailyBannerImpressionsPipeline( $from, $to );
echo " - Working on Banner Impressions", PHP_EOL;
$data = $dao->aggregate(
StatisticModel::class,
$pipe,
['cursor' => true]
);
foreach ($data as $elem) {
AnalyticsHelper::multiBannerImpression(
$elem->_id->banner,
$elem->_id->date->day,
$elem->_id->date->month,
$elem->_id->date->year,
$elem->visualizzazioni
);
}
$pipe = getDailyBannerClicksPipeline( $from, $to );
echo " - Working on Banner Clicks", PHP_EOL;
$data = $dao->aggregate(
StatisticModel::class,
$pipe,
['cursor' => true]
);
foreach ($data as $elem) {
AnalyticsHelper::multiBannerClick(
$elem->_id->banner,
$elem->_id->date->day,
$elem->_id->date->month,
$elem->_id->date->year,
$elem->visualizzazioni
);
}
}
}
?>
+48 -91
View File
@@ -39,22 +39,22 @@ class AnalyticsHelper {
);
}
public static function pageImpression($content, $d, $m, $y, $isNewToday, $isNewMonth, $isNewAbsolute) {
public static function multiPageImpression($content, $d, $m, $y, $incViews = 1, $incToday = 0, $incMonth = 0, $incAbsolute = 0) {
$dao = GlobalVariables::get("dao");
if ($dao instanceof GenericDao) {
$upd = [
'$inc' => [
'views' => 1
'views' => $incViews
]
];
if ($isNewAbsolute || $isNewMonth || $isNewToday) {
$upd['$inc']['dayNewVisitors'] = 1;
if ($incToday > 0) {
$upd['$inc']['dayNewVisitors'] = $incToday;
}
if ($isNewAbsolute || $isNewMonth) {
$upd['$inc']['monthNewVisitors'] = 1;
if ($incMonth > 0) {
$upd['$inc']['monthNewVisitors'] = $incMonth;
}
if ($isNewAbsolute) {
$upd['$inc']['absNewVisitors'] = 1;
if ($incAbsolute > 0) {
$upd['$inc']['absNewVisitors'] = $incAbsolute;
}
$dao->rawUpsert(
PageViewStatsModel::class,
@@ -64,6 +64,19 @@ class AnalyticsHelper {
}
}
public static function pageImpression($content, $d, $m, $y, $isNewToday, $isNewMonth, $isNewAbsolute) {
self::multiPageImpression(
$content,
$d,
$m,
$y,
1,
$isNewAbsolute || $isNewMonth || $isNewToday ? 1 : 0,
$isNewAbsolute || $isNewMonth ? 1 : 0,
$isNewAbsolute ? 1 : 0
);
}
/**
* La funzione si occupa del salvataggio vero e proprio della impression della pagina.
* UTILIZZARE QUESTA FUNZIONE SOLO NELLA PAGINA DI BACKEND (stats/pageImpression.php). Nelle pagine base utilizzare invece la funzione di log
@@ -99,8 +112,7 @@ class AnalyticsHelper {
GUIHandler::addOnLoadJsEvent($function);
}
public static function notiziaImpression($content, $d, $m, $y) {
public static function multiNotiziaImpression($content, $d, $m, $y, $incViews) {
$dao = GlobalVariables::get("dao");
if ($dao instanceof GenericDao) {
$dao->rawUpsert(
@@ -108,12 +120,16 @@ class AnalyticsHelper {
ArticleStatsModel::getFilter($content, $d, $m, $y),
[
'$inc' => [
'views' => 1
'views' => $incViews
]
]
);
}
}
public static function notiziaImpression($content, $d, $m, $y) {
self::multiNotiziaImpression($content, $d, $m, $y, 1);
}
/**
* La funzione si occupa del salvataggio vero e proprio della impression della notizia.
@@ -160,7 +176,7 @@ class AnalyticsHelper {
}
public static function bannerImpression($bannerId, $d, $m, $y) {
public static function multiBannerImpression($bannerId, $d, $m, $y, $views) {
$dao = GlobalVariables::get("dao");
if ($dao instanceof GenericDao) {
$dao->rawUpsert(
@@ -168,25 +184,32 @@ class AnalyticsHelper {
BannerStatsModel::getFilter($bannerId, $d, $m, $y),
[
'$inc' => [
'views' => 1
'views' => $views
]
]
);
}
}
public static function bannerImpression($bannerId, $d, $m, $y) {
self::multiBannerImpression($bannerId, $d, $m, $y, 1);
}
public static function multiBannerClick($bannerId, $d, $m, $y, $clicks) {
$dao = GlobalVariables::get("dao");
if ($dao instanceof GenericDao) {
$dao->rawUpsert(
BannerStatsModel::class,
BannerStatsModel::getFilter($bannerId, $d, $m, $y),
[
'$inc' => [
'clicks' => $clicks
]
]
);
}
}
public static function bannerClick($bannerId, $d, $m, $y) {
$dao = GlobalVariables::get("dao");
if ($dao instanceof GenericDao) {
$dao->rawUpsert(
BannerStatsModel::class,
BannerStatsModel::getFilter($bannerId, $d, $m, $y),
[
'$inc' => [
'clicks' => 1
]
]
);
}
self::multiBannerClick($bannerId, $d, $m, $y, 1);
}
/**
@@ -275,72 +298,6 @@ class AnalyticsHelper {
return sizeof($ret) == 0 ? 0 : $ret[0]['tot'];
}
/**
* Restituisce il banner da mostrare tenendo in considerazione quelli già visualizzati e le visualizzazioni totali
* @param int $position
* @param string $replaced id del banner rimpiazzato
*/
public static function getBannerToShow($position, $replaced = null, $category = BannerModel::GENERAL_CATEGORY) {
// ?TODO: Ragionaci
// Rimuovi il replaced dalla lista
$shown = array();
$rval = null;
if (ASDSessionHandler::sessionValueExists("bannerActive")){
$shown = ASDSessionHandler::getSessionValue("bannerActive");
if (!is_null($replaced) && in_array($replaced, $shown)){
$key = array_search($replaced, $shown);
unset($shown[$key]);
ASDSessionHandler::setSessionValue("bannerActive",$shown);
}
}
// idlist contiene gli id dei banner in ordine di visualizzazione crescente (esclusi quelli non visualizzati)
$pipeline = PipelineHelper::getTodaysBannerVisualizationPipeline($position);
$stats = GlobalVariables::get("dao")->aggregate("StatisticModel",$pipeline);
// var_dump($stats);
$idList = array();
if (sizeof($stats)>0){
foreach ($stats as $stat){
$idList[] = $stat["_id"]["banner"];
}
}
// $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 CET") * 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 MongoDB\BSON\ObjectID($id);}, $todayPlusShown);
$tmp = array('_id'=>array('$nin'=>$tmp));
$rval = GlobalVariables::get("dao")->getFirst("BannerModel", array_merge($baseSearchArray, $tmp) );
}
else {
$rval = GlobalVariables::get("dao")->getFirst("BannerModel", $baseSearchArray);
}
if (is_null($rval)){
$todayLessShown = array_values(array_diff($idList, $shown));
if (sizeof($todayLessShown)>0){
$i = 0;
while (is_null($rval) && $i<sizeof($todayLessShown)){
$condition = array_merge($baseSearchArray, array("id"=>$todayLessShown[$i]) );
$rval = GlobalVariables::get("dao")->getFirst("BannerModel", $condition );
$i++;
}
}
}
if (!is_null($rval)){
$shown[] = $rval->id;
ASDSessionHandler::setSessionValue("bannerActive",$shown);
}
return $rval;
}
}
?>
+13 -7
View File
@@ -257,14 +257,20 @@ class GenericDao{
'allowDiskUse' => true
] );
$cursor = $this->client->executeCommand( $this->dbName, $command );
if (array_key_exists('cursor', $options) && $options['cursor'] == true) {
return $cursor;
}
else {
$rval = [];
foreach ($cursor as $ele){ // inganniamo il cursore, in realtà il risultato è uno
//TODO CHECK
$rval[] = json_decode( json_encode($ele) ,true );
}
return $rval;
}
$rval = [];
foreach ($cursor as $ele){ // inganniamo il cursore, in realtà il risultato è uno
//TODO CHECK
$rval[] = json_decode( json_encode($ele) ,true );
}
return $rval;
}
+58 -20
View File
@@ -6,22 +6,58 @@
*/
class ImageCacheManager {
private static $memcached = null;
const EXPIRATION_SECONDS = 2592000; // 30 * 24 * 60 * 60 -> 30 gg
private static function getMemcached() {
if (is_null(self::$memcached)) {
self::$memcached = new Memcached();
self::$memcached->addServer('memcached', 11211);
}
return self::$memcached;
}
private static function getImageKey(MediaModel $media, $size) {
return self::getImageKeyById($media->id, $size);
}
private static function getImageKeyById(string $id, $size) {
return $id."-".$size."-image";
}
private static function getMimeKey(MediaModel $media, $size) {
return self::getMimeKeyById($media->id, $size);
}
private static function getMimeKeyById(string $id, $size) {
return $id."-".$size."-mime";
}
public static function cacheImage(MediaModel $media, $size){
self::checkValidModel($media);
$cachedPath = self::getImageCachePath($media->id, $size);
$mimePath = self::getImageMimePath($media->id, $size);
// $cachedPath = self::getImageCachePath($media->id, $size);
// $mimePath = self::getImageMimePath($media->id, $size);
$originalFilePath = self::getOriginalPath($media);
if ( SFSManager::fileExists($cachedPath) ){
SFSManager::deleteFile($cachedPath);
SFSManager::deleteFile($mimePath);
}
if (!is_dir(pathinfo($cachedPath,PATHINFO_DIRNAME))){
SFSManager::createDirectory(pathinfo($cachedPath,PATHINFO_DIRNAME));
}
SFSManager::writeFile(mime_content_type($originalFilePath), $mimePath);
SFSManager::writeFile(self::getImageContent($media, $size), $cachedPath);
// if ( SFSManager::fileExists($cachedPath) ){
// SFSManager::deleteFile($cachedPath);
// SFSManager::deleteFile($mimePath);
// }
// if (!is_dir(pathinfo($cachedPath,PATHINFO_DIRNAME))){
// SFSManager::createDirectory(pathinfo($cachedPath,PATHINFO_DIRNAME));
// }
// SFSManager::writeFile(mime_content_type($originalFilePath), $mimePath);
// SFSManager::writeFile(self::getImageContent($media, $size), $cachedPath);
self::getMemcached()->set(
self::getMimeKey($media, $size),
mime_content_type($originalFilePath),
self::EXPIRATION_SECONDS
);
self::getMemcached()->set(
self::getImageKey($media, $size),
self::getImageContent($media, $size),
self::EXPIRATION_SECONDS
);
}
/**
@@ -30,8 +66,9 @@ class ImageCacheManager {
* @param int $size
*/
public static function isCached($id, $size){
$cachedPath = self::getImageCachePath($id, $size);
return SFSManager::fileExists($cachedPath);
return self::getMemcached()->get(self::getImageKeyById($id, $size)) ? true : false;
// $cachedPath = self::getImageCachePath($id, $size);
// return SFSManager::fileExists($cachedPath);
}
@@ -43,8 +80,9 @@ class ImageCacheManager {
* @return string
*/
public static function getMimeType($id, $size){
$mimePath = self::getImageMimePath($id, $size);
return file_get_contents($mimePath);
return self::getMemcached()->get(self::getMimeKeyById($id, $size));
// $mimePath = self::getImageMimePath($id, $size);
// return file_get_contents($mimePath);
}
/**
@@ -54,14 +92,14 @@ class ImageCacheManager {
* @return string
*/
public static function getContent($id, $size){
$cachedPath = self::getImageCachePath($id, $size);
return file_get_contents($cachedPath);
return self::getMemcached()->get(self::getImageKeyById($id, $size));
// $cachedPath = self::getImageCachePath($id, $size);
// return file_get_contents($cachedPath);
}
public static function printCachedMedia($id, $size){
$cachedPath = self::getImageCachePath($id, $size);
public static function printCachedMedia($id, $size) {
header('Content-type: '.self::getMimeType($id, $size));
return readfile($cachedPath);
echo self::getContent($id, $size);
}
+2 -2
View File
@@ -17,7 +17,7 @@ if (array_key_exists("id",$_GET)) {
$size=intval($_GET['size']);
}
if ($size == 3){
if ($size !== MediaImage::SIZE_ORIGINAL){
if (!ImageCacheManager::isCached($_GET["id"], $size)){
$img = GlobalVariables::get("dao")->getFirst("MediaModel",array("id"=>$_GET['id']));
if (!is_null($img)){
@@ -32,8 +32,8 @@ if (array_key_exists("id",$_GET)) {
else {
$img = GlobalVariables::get("dao")->getFirst("MediaModel",array("id"=>$_GET['id']));
$basepath = GlobalVariables::get("config")->paths->media;
if (!is_null($img) && file_exists($basepath."/".$img->id.".".$img->extension)){
$basepath = GlobalVariables::get("config")->paths->media;
$toMime = $basepath."/".$img->id.".".$img->extension;
$thumb = new Imagick($basepath."/".$img->id.".".$img->extension);
+12 -12
View File
@@ -209,7 +209,7 @@ catch (Exception $ex){
if(!is_null($media)){
?>
<div class="ansaImage mediaContent">
<?php $media->renderMedia();?>
<?php $media->renderMedia(['size' => MediaImage::SIZE_BIG]);?>
</div>
<?php
}
@@ -246,7 +246,7 @@ catch (Exception $ex){
<div id="politica_<?php echo $i;?>" class="newsSummary"><?php
$media = DaoMediaHandler::getMainMediaFromModel($politica);
if(!is_null($media)){?>
<div class="newsMainMedia mediaContent"><?php $media->renderMedia();?></div>
<div class="newsMainMedia mediaContent"><?php $media->renderMedia(['size' => MediaImage::SIZE_BIG]);?></div>
<?php }?>
<div class="newsTitle"><?php echo $stringTitolo;?></div>
<div class="newsSubTitle"><?php echo $string;?></div>
@@ -276,7 +276,7 @@ catch (Exception $ex){
<div id="cronaca_<?php echo $i;?>" class="newsSummary"><?php
$media = DaoMediaHandler::getMainMediaFromModel($cronaca);
if(!is_null($media)){?>
<div class="newsMainMedia mediaContent"><?php $media->renderMedia();?></div>
<div class="newsMainMedia mediaContent"><?php $media->renderMedia(['size' => MediaImage::SIZE_BIG]);?></div>
<?php }?>
<div class="newsTitle"><?php echo $stringTitolo;?></div>
<div class="newsSubTitle"><?php echo $string;?></div>
@@ -305,7 +305,7 @@ catch (Exception $ex){
<div id="sport_<?php echo $i;?>" class="sportSummary"><?php
$media = DaoMediaHandler::getMainMediaFromModel($sport);
if(!is_null($media)){?>
<div class="newsMainMedia mediaContent"><?php $media->renderMedia();?></div>
<div class="newsMainMedia mediaContent"><?php $media->renderMedia(['size' => MediaImage::SIZE_BIG]);?></div>
<?php }?>
<div class="newsTitle"><?php echo $stringTitolo;?></div>
<div class="newsSubTitle"><?php echo $string;?></div>
@@ -334,7 +334,7 @@ catch (Exception $ex){
<a href="<?php echo $cultura->getAbsoluteUrl();?>" id="cultura_<?php echo $i;?>" class="culturaNews"><?php
$media = DaoMediaHandler::getMainMediaFromModel($cultura);
if(!is_null($media)){?>
<div class="culturaMainMedia mediaContent"><?php $media->renderMedia();?></div>
<div class="culturaMainMedia mediaContent"><?php $media->renderMedia(['size' => MediaImage::SIZE_MEDIUM]);?></div>
<?php }?>
<div class="culturaTitle"><?php echo $string;?></div>
</a>
@@ -358,7 +358,7 @@ catch (Exception $ex){
<a href="<?php echo $ristoranti->getAbsoluteUrl();?>" id="ristoranti_<?php echo $i;?>" class="ristorantiBlock"><?php
$media = DaoMediaHandler::getMainMediaFromModel($ristoranti);
if(!is_null($media)){?>
<div class="culturaMainMedia mediaContent"><?php $media->renderMedia();?></div>
<div class="culturaMainMedia mediaContent"><?php $media->renderMedia(['size' => MediaImage::SIZE_MEDIUM]);?></div>
<?php }?>
<div class="ristorantiTitle"><?php echo $string;?></div>
</a>
@@ -381,7 +381,7 @@ catch (Exception $ex){
<a href="<?php echo $salute->getAbsoluteUrl();?>" id="salute_<?php echo $i;?>" class="saluteContainer">
<?php $media = DaoMediaHandler::getMainMediaFromModel($salute);
if(!is_null($media)){?>
<div class="culturaMainMedia mediaContent"><?php $media->renderMedia();?></div>
<div class="culturaMainMedia mediaContent"><?php $media->renderMedia(['size' => MediaImage::SIZE_MEDIUM]);?></div>
<?php }?>
<div class="saluteTitle"><?php echo $stringTitle;?></div>
</a>
@@ -430,7 +430,7 @@ catch (Exception $ex){
<a href="<?php echo $gossip->getAbsoluteUrl();?>" id="gossip_<?php echo $i;?>"class="gossipContainer">
<?php $media = DaoMediaHandler::getMainMediaFromModel($gossip);
if(!is_null($media)){?>
<div class="culturaMainMedia mediaContent"><?php $media->renderMedia();?></div>
<div class="culturaMainMedia mediaContent"><?php $media->renderMedia(['size' => MediaImage::SIZE_MEDIUM]);?></div>
<?php }?>
<div class="gossipTitle"><?php echo $stringTitle;?></div>
</a>
@@ -455,7 +455,7 @@ catch (Exception $ex){
<a href="<?php echo $professioni->getAbsoluteUrl();?>" id="gossip_<?php echo $i;?>"class="gossipContainer">
<?php $media = DaoMediaHandler::getMainMediaFromModel($professioni);
if(!is_null($media)){?>
<div class="culturaMainMedia mediaContent"><?php $media->renderMedia();?></div>
<div class="culturaMainMedia mediaContent"><?php $media->renderMedia(['size' => MediaImage::SIZE_MEDIUM]);?></div>
<?php }?>
<div class="gossipTitle"><?php echo $stringTitle;?></div>
</a>
@@ -479,7 +479,7 @@ catch (Exception $ex){
<a href="<?php echo $elezioni->getAbsoluteUrl();?>" class="animaliContainer">
<?php $media = DaoMediaHandler::getMainMediaFromModel($elezioni);
if(!is_null($media)){?>
<div class="culturaMainMedia mediaContent"><?php $media->renderMedia();?></div>
<div class="culturaMainMedia mediaContent"><?php $media->renderMedia(['size' => MediaImage::SIZE_MEDIUM]);?></div>
<?php }?>
<div class="viaggiTitle"><?php echo $stringTitle;?></div>
</a>
@@ -503,7 +503,7 @@ catch (Exception $ex){
<a href="<?php echo $viaggi->getAbsoluteUrl();?>" id="viaggi_<?php echo $i;?>"class="animaliContainer">
<?php $media = DaoMediaHandler::getMainMediaFromModel($viaggi);
if(!is_null($media)){?>
<div class="culturaMainMedia mediaContent"><?php $media->renderMedia();?></div>
<div class="culturaMainMedia mediaContent"><?php $media->renderMedia(['size' => MediaImage::SIZE_MEDIUM]);?></div>
<?php }?>
<div class="viaggiTitle"><?php echo $stringTitle;?></div>
</a>
@@ -525,7 +525,7 @@ catch (Exception $ex){
<a href="<?php echo $animalNews->getAbsoluteUrl();?>" class="animaliContainer">
<?php $media = DaoMediaHandler::getMainMediaFromModel($animalNews);
if(!is_null($media)){?>
<div class="culturaMainMedia mediaContent"><?php $media->renderMedia();?></div>
<div class="culturaMainMedia mediaContent"><?php $media->renderMedia(['size' => MediaImage::SIZE_MEDIUM]);?></div>
<?php }?>
<div class="animaliTitle"><?php echo $stringTitle;?></div>
</a>
+1 -1
View File
@@ -154,7 +154,7 @@ body{font-family:lato, arial;}
.headArticolo .newsImage{width:100vw;text-align:center;overflow:hidden;}
.headArticolo .newsImage img{max-width:100%;}
.articoloTitle{width:90%;padding:10px;margin:auto;}
.articoloTitle .title{font-weight:bold;color:black;}
.articoloTitle .title{ font-weight:bold; color:black; }
.articoloTitle .subTitle{font-weight:italic;color:#9a9a9a;}
.articoloBody{width:90vw;margin:auto;}
.articoloBody .articoloTesto{text-align:justify;padding:5px;}
@@ -13,19 +13,20 @@ services:
max-file: "5"
max-size: "50m"
webserver:
image: §PROJECT_REPOSITORY§/§PROJECT_GROUP§/§PROJECT_BUILDNAME§:§TAG_NAME§
image: §PROJECT_REPOSITORY§/§PROJECT_GROUP§/§PROJECT_BUILDNAME§:§TAG_NAME§-webserver
env_file:
- environments/common/webserver.env
- environments/production/webserver.env
- environments/§ENVIRONMENT_TYPE§/webserver.env
depends_on:
- mongo
- memcached
restart: "on-failure:3"
ports:
- "80:80"
networks:
db-network:
§PROJECT_BUILDNAME§-network:
nginx-network:
aliases:
- §PROJECT_BUILDNAME§.§ENVIRONMENT_TYPE§.webserver
links:
- mongo:database
volumes:
@@ -65,6 +66,10 @@ services:
networks:
db-network:
§PROJECT_BUILDNAME§-network:
nginx-network:
external: true
name:
nginx-network
volumes:
-4
View File
@@ -49,10 +49,6 @@ services:
§PROJECT_BUILDNAME§-network:
networks:
nginx-network:
external:
name:
nginx-network
db-network:
§PROJECT_BUILDNAME§-network:
+1 -3
View File
@@ -3,7 +3,5 @@ DDNINJA_IS_PRODUCTION=true
DDNINJA_MONGO_DBNAME=fdn2
DDNINJA_MONGO_LOCATION=database
DDNINJA_MONGO_USER=fdn2
DDNINJA_MONGO_PASSWORD=p14n3ll1FDN2
DDNINJA_PUBLIC_URL=http://www.ifattidinapoli.it
DDNINJA_PUBLIC_URL=http://preproduction.ifattidinapoli.it
+19
View File
@@ -0,0 +1,19 @@
version: "3"
services:
nginx:
image: nginx:1.16
ports:
- "80:80"
- "443:443"
networks:
- nginx-network
restart: always
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
networks:
nginx-network:
external: true
name:
nginx-network
+32
View File
@@ -0,0 +1,32 @@
worker_processes 1;
events { worker_connections 1024; }
http {
client_max_body_size 5M;
server {
listen 80;
server_name www.ifattidinapoli.it preproduction.ifattidinapoli.it default_server;
location / {
proxy_pass http://fdn2.production.webserver/;
proxy_redirect off;
proxy_set_header Host $host;
}
}
server {
listen 80;
server_name test.ifattidinapoli.it;
location / {
proxy_pass http://fdn2.test.webserver/;
proxy_redirect off;
proxy_set_header Host $host;
}
}
}
+65 -6
View File
@@ -22,8 +22,14 @@ usage() {
echo " -u: Unit tests locally" 1>&2;
echo " -d: Run debug vesion locally" 1>&2;
echo " -p: Publish (requires a version)" 1>&2;
echo " -X: Staging Deploy (requires a version)" 1>&2;
echo " -x: Production Deploy (requires a version)" 1>&2;
echo " -t: Software version, this will be used for the docker tag (default: local)" 1>&2;
echo " Tagging, docker images (default: local)" 1>&2;
echo " -t: Manual tag" 1>&2;
echo " -T: Autotag patch/release" 1>&2;
echo " -m: Autotag minor" 1>&2;
echo " -M: Autotag major" 1>&2;
echo " -P: Pre-release" 1>&2;
echo " -v: Verbose" 1>&2;
exit 1;
}
@@ -31,12 +37,16 @@ usage() {
UNIT_MODE=0
DEBUG_MODE=0
PUBLISH_MODE=0
DEPLOY_MODE=0
DEPLOY_TEST_MODE=0
DEPLOY_PROD_MODE=0
SELECTED_MODES=0
TAG_IMPLICIT=1
TAG="local"
TAG_OPTS=""
AUTOTAG=0
while getopts "t:hvudpx" o; do
while getopts "t:TmMPhvudpxX" o; do
case "${o}" in
u)
UNIT_MODE=1
@@ -50,13 +60,38 @@ while getopts "t:hvudpx" o; do
PUBLISH_MODE=1
SELECTED_MODES+=1
;;
X)
DEPLOY_TEST_MODE=1
SELECTED_MODES+=1
;;
x)
DEPLOY_MODE=1
DEPLOY_PROD_MODE=1
SELECTED_MODES+=1
;;
t)
TAG=${OPTARG}
TAG_IMPLICIT=0
;;
T)
TAG_OPTS="${TAG_OPTS}r"
TAG_IMPLICIT=0
AUTOTAG=1
;;
m)
TAG_OPTS="${TAG_OPTS}m"
TAG_IMPLICIT=0
AUTOTAG=1
;;
M)
TAG_OPTS="${TAG_OPTS}M"
TAG_IMPLICIT=0
AUTOTAG=1
;;
P)
TAG_OPTS="${TAG_OPTS}p"
TAG_IMPLICIT=0
AUTOTAG=1
;;
v)
VERBOSE=1
@@ -81,6 +116,11 @@ if [[ $SELECTED_MODES -ne 1 ]]; then
usage
fi
if [[ $AUTOTAG -eq 1 ]]; then
TAG=`./next-ver.sh -${TAG_OPTS}`
echo "Using tag $TAG"
fi
./aws-login.sh
if [[ $UNIT_MODE -eq 1 ]]; then
@@ -109,6 +149,11 @@ if [[ $PUBLISH_MODE -eq 1 ]]; then
./run-unit.sh $VERBOPT -t $TAG
./publish.sh $VERBOPT -t $TAG
if [[ $TAG_IMPLICIT -ne 1 ]]; then
git tag $TAG
git push --tags
fi
fi
@@ -134,9 +179,23 @@ if [[ $DEBUG_MODE -eq 1 ]]; then
xdg-open "$DDNINJA_PUBLIC_URL"
fi
if [[ $DEPLOY_TEST_MODE -eq 1 ]]; then
if [[ $AUTOTAG -eq 1 ]]; then
TAG=`./latest-ver.sh -${TAG_OPTS}`
fi
OUT_FOLDER="/home/$PROJECT_AUTHOR/$PROJECT_BUILDNAME/test"
mkdir -p $OUT_FOLDER
./generateComposeFolder.sh -s -o "$OUT_FOLDER" -t $TAG
cd "$OUT_FOLDER"
docker compose up -d
fi
if [[ $DEPLOY_MODE -eq 1 ]]; then
OUT_FOLDER="/home/$PROJECT_AUTHOR/$PROJECT_BUILDNAME/local"
if [[ $DEPLOY_PROD_MODE -eq 1 ]]; then
if [[ $AUTOTAG -eq 1 ]]; then
TAG=`./latest-ver.sh -${TAG_OPTS}`
fi
OUT_FOLDER="/home/$PROJECT_AUTHOR/$PROJECT_BUILDNAME/production"
mkdir -p $OUT_FOLDER
./generateComposeFolder.sh -p -o "$OUT_FOLDER" -t $TAG
+6 -3
View File
@@ -33,6 +33,7 @@ usage() {
STARTING_FILE=""
CFGFILE="$DIR/../config"
OUT_DIRECTORY=""
ENV_TYPE="local"
SELECTED_MODES=0
@@ -47,11 +48,13 @@ while getopts "i:o:t:hvlLsp" o; do
SELECTED_MODES+=1
;;
s)
STARTING_FILE="$DIR/../cicd/docker-compose/test.yml"
STARTING_FILE="$DIR/../cicd/docker-compose/deploy.yml"
ENV_TYPE="test"
SELECTED_MODES+=1
;;
p)
STARTING_FILE="$DIR/../cicd/docker-compose/production.yml"
STARTING_FILE="$DIR/../cicd/docker-compose/deploy.yml"
ENV_TYPE="production"
SELECTED_MODES+=1
;;
i)
@@ -89,5 +92,5 @@ fi
cp -rT "$DIR/../cicd/environments" "$OUT_DIRECTORY/environments"
buildTemplate -f "$CFGFILE" -t "$STARTING_FILE" -o "$OUT_DIRECTORY/docker-compose.yml" --add TAG_NAME=$TAG
buildTemplate -f "$CFGFILE" -t "$STARTING_FILE" -o "$OUT_DIRECTORY/docker-compose.yml" --add TAG_NAME=$TAG --add ENVIRONMENT_TYPE=$ENV_TYPE
+3
View File
@@ -0,0 +1,3 @@
#!/bin/bash
git tag -l --sort=-version:refname | head -n 1
+59
View File
@@ -0,0 +1,59 @@
#!/bin/bash
usage() {
echo "Usage: $0 [-h] [-m|M] [-p]" 1>&2;
echo " -h: This message" 1>&2;
echo " -p: Pre release" 1>&2;
echo " -m: Increment minor" 1>&2;
echo " -M: Increment major" 1>&2;
}
PRE_RELEASE=0
ALTERS=0
ALTER_NAME="release"
while getopts "hpmMr" o; do
case "${o}" in
p)
PRE_RELEASE=1
;;
r)
ALTERS=$ALTERS+1
ALTER_NAME="release"
;;
m)
ALTERS=$ALTERS+1
ALTER_NAME="minor"
;;
M)
ALTERS=$ALTERS+1
ALTER_NAME="major"
;;
h)
usage
exit 0;
;;
*)
printerr "Unsupported option ${o}"
usage
exit 1;
;;
esac
done
if [[ $ALTERS -gt 1 ]]; then
echo "You can specify exactly one option between m and M"
usage
exit 1;
fi
CURRENT_VERSION=`./latest-ver.sh`
INCREMENT_NAME=$ALTER_NAME
if [[ $PRE_RELEASE -gt 0 ]]; then
INCREMENT_NAME="pre$INCREMENT_NAME"
fi
NEW_VERSION=`semver $CURRENT_VERSION --preid rc -i $INCREMENT_NAME`
echo "$NEW_VERSION"