Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /************************************************************
- ad.host.class.php
- Product : Digital Asset
- Version : 1.0
- Release : 0
- Date Created : Fri Mar 12 16:09:28 EET 2010
- Developed By : Kamil Baderddine PHP Department LayoutLTD
- All Rights Reserved , Layout LTD COPYRIGHT 2010
- Page Description :
- ************************************************************/
- class EasyNewsManager extends request{
- var $sl_id = null;
- var $kv_db_server = null;
- var $kv_db = null;
- var $kv_db_user = null;
- var $kv_limit = null;
- var $kv_type = null;
- var $kv_password = null;
- var $mssql;
- var $sl_paths;
- var $log_folder;
- var $log_file;
- /**
- * Class Constructor
- *
- * @return KVManager
- */
- function EasyNewsManager ( $variable_intialization_array )
- {
- $this->SetSLID( $variable_intialization_array['sl_id'] );
- $this->SetDBServer( $variable_intialization_array['kv_db_server'] );
- $this->SetDBName( $variable_intialization_array['kv_db'] );
- $this->SetDBUser( $variable_intialization_array['kv_db_user'] );
- $this->SetLimit( $variable_intialization_array['kv_limit'] );
- $this->SetType( $variable_intialization_array['kv_type'] );
- $this->SetDBPassword( $variable_intialization_array['kv_password'] );
- $this->SetLogFolder( URLHelper::BuildMaintenanceLogsPath() . "archive_migration/" );
- $this->SetLogFile( URLHelper::BuildMaintenanceLogsFileName() );
- $this->categories_ids = array();
- $this->categories_ids['PublicationName'] = 17;
- $this->categories_ids['PublicationDate'] = 21;
- $this->categories_ids['PageNb'] = 24;
- $this->categories_ids['Caption'] = 26;
- $this->categories_ids['Keywords'] = 2;
- $this->categories_ids['Description'] = 3;
- $this->categories_ids['VIP_Name'] = 34;
- $this->categories_ids['PlaceOfBirth'] = 35;
- $this->categories_ids['BirthDate'] = 36;
- $this->categories_ids['CurriculumVitae'] = 37;
- $this->categories_ids['NickName'] = 38;
- $this->connect_mssql();
- }
- function connect_mssql()
- {
- $conn_array = array
- (
- "UID" => $this->GetDBUser(),
- "PWD" => $this->GetDBPassword(),
- "Database" => $this->GetDBName(),
- "ReturnDatesAsStrings" => true,
- 'CharacterSet' => 'UTF-8'
- );
- $this->mssql = mssql_connect($this->GetDBServer(), $this->GetDBUser(), $this->GetDBPassword());
- if (!$this->mssql || !mssql_select_db($this->GetDBName(), $this->mssql))
- {
- die( print_r( sqlsrv_errors(), true ) );
- }
- }
- function query_mssql($query)
- {
- return $result = mssql_query( $query );
- }
- function fetch_mssql( $result )
- {
- $row = mssql_fetch_object( $result );
- return $row;
- }
- /**
- * Set Log Folder Path
- *
- * @param Int $log_folder_path
- */
- function SetLogFolder( $log_folder_path )
- {
- $this->log_folder = $log_folder_path;
- }
- /**
- * Get Log Folder Path
- *
- * @return String
- */
- function GetLogFolder()
- {
- return $this->log_folder;
- }
- /**
- * Set Log File Name
- *
- * @param Int $log_file
- */
- function SetLogFile( $log_file )
- {
- $this->log_file = $log_file;
- }
- /**
- * Get Log File Name
- *
- * @return String
- */
- function GetLogFile()
- {
- return $this->log_file;
- }
- /**
- * Set sl_id
- *
- * @param Int $log_folder_path
- */
- function SetSLID( $sl_id )
- {
- $this->sl_id = $sl_id;
- }
- /**
- * Get sl_id
- *
- * @return String
- */
- function GetSLID()
- {
- return $this->sl_id;
- }
- /**
- * Set $kv_db_server
- *
- * @param Int $kv_db_server
- */
- function SetDBServer( $kv_db_server )
- {
- $this->kv_db_server = $kv_db_server;
- }
- /**
- * Get kv_db_server
- *
- * @return String
- */
- function GetDBServer()
- {
- return $this->kv_db_server;
- }
- /**
- * Set $kv_db
- *
- * @param Int $kv_db
- */
- function SetDBName( $kv_db )
- {
- $this->kv_db = $kv_db;
- }
- /**
- * Get kv_db
- *
- * @return String
- */
- function GetDBName()
- {
- return $this->kv_db;
- }
- /**
- * Set $kv_db_user
- *
- * @param Int $kv_db_user
- */
- function SetDBUser( $kv_db_user )
- {
- $this->kv_db_user = $kv_db_user;
- }
- /**
- * Get $kv_db_user
- *
- * @return String
- */
- function GetDBUser()
- {
- return $this->kv_db_user;
- }
- /**
- * Set $kv_limit
- *
- * @param Int $kv_limit
- */
- function SetLimit( $kv_limit )
- {
- $this->kv_limit = $kv_limit;
- }
- /**
- * Get $kv_db_user
- *
- * @return String
- */
- function GetLimit()
- {
- return $this->kv_limit;
- }
- /**
- * Set $kv_type
- *
- * @param Int $kv_type
- */
- function SetType( $kv_type )
- {
- $this->kv_type = $kv_type;
- }
- /**
- * Get $kv_db_user
- *
- * @return String
- */
- function GetType()
- {
- return $this->kv_type;
- }
- /**
- * Set $kv_password
- *
- * @param Int $kv_password
- */
- function SetDBPassword( $kv_password )
- {
- $this->kv_password = $kv_password;
- }
- /**
- * Get $kv_password
- *
- * @return String
- */
- function GetDBPassword()
- {
- return $this->kv_password;
- }
- /**
- * Fill storage location ids
- *
- */
- function FillSLIDS()
- {
- $storage_manager_obj = new StorageManager();
- $storage_manager_obj->members_array = array( "sl.sl_id", "sl.sl_path" );
- $query_more = "";
- $storage_manager_obj->GetStorageLocations( $query_more );
- for( $i = 0 ; $i < $storage_manager_obj->count ; $i++ )
- {
- $this->SetSLPaths( $storage_manager_obj->data["sl_sl_path"][$i], $storage_manager_obj->data["sl_sl_id"][$i] );
- }
- }
- /**
- * Set SL Paths
- *
- * @param Int $row_date
- */
- function SetSLPaths( $sl_path, $sl_id )
- {
- $this->sl_paths[ $sl_id ] = $sl_path;
- }
- /**
- * Manage KV
- *
- */
- function ManageKVTypes()
- {
- switch ( $this->GetType() )
- {
- case "en_create_npp_files":
- {
- echo "\n\n" . date('H:i:s') . " create npp files Launched\n\n";
- $this->CreateNPPFiles();
- echo "\n\n" . date('H:i:s') . " create npp files Finished\n\n";
- }
- break;
- case "en_link_files":
- {
- echo "\n\n" . date('H:i:s') . " link files Launched\n\n";
- $this->LinkFiles();
- echo "\n\n" . date('H:i:s'). " files linked, article metadata updated\n\n";
- }
- case "en_link_pdf_files":
- {
- echo "\n\n" . date('H:i:s') . " link pdf files Launched\n\n";
- $this->LinkPDFFiles();
- echo "\n\n" . date('H:i:s'). " files linked\n\n";
- }
- break;
- case "en_update_categories":
- {
- echo "\n\n" . date('H:i:s'). " updating MediaFiles metadata\n\n";
- $this->UpdateMediaFilesMetaData();
- echo "\n\n" . date('H:i:s'). " MediaFiles metadata update Finished\n\n";
- sleep( 10000000 );
- echo "\n\n" . date('H:i:s'). " updating PageFiles metadata\n\n";
- //$this->UpdatePageFilesMetaData();
- echo "\n\n" . date('H:i:s'). " PageFiles metadata update Finished\n\n";
- }
- break;
- case "en_vip_data":
- {
- echo "\n\n" . date('H:i:s'). " updating Vip metadata\n\n";
- $this->UpdateVipFilesMetaData();
- echo "\n\n" . date('H:i:s'). " Vip metadata update Finished\n\n";
- sleep( 10000000 );
- }
- break;
- }
- }
- function LinkFiles()
- {
- global $tableCollab, $config;
- $file_manager_obj = new FileManager();
- $meta_data_types = new MetaDataTypes();
- $categories_obj = new Categories();
- $a7_base_dir = array();
- $this->FillSLIDS();
- $article_count = 0;
- $article_id = 0;
- {/** select total result */
- $result_total = $this->query_mssql("SELECT count(*)
- FROM [" . $this->GetDBName() . "].[dbo].[Article]
- left join [" . $this->GetDBName() . "].[dbo].[Publication] on Article.PublicationId = Publication.PublicationId
- left join [" . $this->GetDBName() . "].[dbo].[Category] on Article.CategoryId = Category.CategoryId
- left join [" . $this->GetDBName() . "].[dbo].[Author] on Article.AuthorId = Author.AuthorId");
- $articles_count = $this->fetch_mssql( $result_total );
- $total_count = $articles_count->computed;
- echo $total_count;
- }
- while ( $article_count < $total_count )
- {
- $result = $this->query_mssql("SELECT TOP 100 Publication.Name as Publication_Name, Category.Name as Section_Name, Author.Name as Author_Name, Article.ArticleId
- , Article.PublicationDate, Article.PublicationId, Article.PageNb
- FROM [" . $this->GetDBName() . "].[dbo].[Article]
- left join [" . $this->GetDBName() . "].[dbo].[Publication] on Article.PublicationId = Publication.PublicationId
- left join [" . $this->GetDBName() . "].[dbo].[Category] on Article.CategoryId = Category.CategoryId
- left join [" . $this->GetDBName() . "].[dbo].[Author] on Article.AuthorId = Author.AuthorId
- WHERE Article.ArticleId > " . $article_id);
- while( $article = $this->fetch_mssql( $result ) )
- {
- $article_count++;
- $article_id = $article->ArticleId;
- $pub_date = date("Y-m-d", strtotime( $article->PublicationDate ) );
- $log_string = " link article : " . $article_id . ".npp" . " (" . $article_count . " of " . $total_count . ")";
- echo $log_string . "\n";
- //get the npp file id
- $sf_path = "./articles/" . str_replace( "-", "/", $pub_date ) . "/" . ( !empty( $article->PublicationId ) ? $article->PublicationId : "no_publication" ) . "/";
- $sf_name = $article_id . ".npp";
- $query_more = " WHERE sf_path='" . $sf_path . "' AND sf_name='" . $sf_name . "' AND fk_sl_id='" . $this->GetSLID() . "'";
- $file_manager_obj->members_array = array( "sf.sf_id", "sf.sf_path", "sf.sf_name", "sf.sf_parent_id", "sf.fk_sl_id" );
- $file_manager_obj->GetFiles( $query_more );
- if( $file_manager_obj->count > 0 )
- {
- $npp_sf_id = $file_manager_obj->data["sf_sf_id"][0];
- $related_file_ids = array();
- $related_file_ids[] = $file_manager_obj->data["sf_sf_id"][0];
- //get articles media files
- $result_media = $this->query_mssql("SELECT MediaType.Name as MediaTypeName, CAST(MediaFile.Path AS TEXT) AS MediaFilePath FROM [" . $this->GetDBName() . "].[dbo].[MediaFile]
- LEFT JOIN [" . $this->GetDBName() . "].[dbo].[MediaType] ON MediaType.MediaTypeId = MediaFile.MediaTypeId
- WHERE MediaFile.ArticleId = " . $article_id );
- $article_media_count = 0;
- while ( $article_media = $this->fetch_mssql( $result_media ) )
- {
- $article_media_count++;
- $media_path_parts = $this->mb_pathinfo( "/" . $article_media->MediaFilePath );
- $media_file_dir = $media_path_parts["dirname"]; //set the file dir
- $media_file_name = $media_path_parts["filename"]; //set the file name
- //SELECT media file id from a7pro with filename and path
- $file_manager_media = new FileManager();
- $file_manager_media->members_array = array( "sf.sf_id", "sf.sf_path", "sf.sf_name", "sf.sf_parent_id", "sf.fk_sl_id" );
- $query_more = " WHERE sf_path LIKE '%" . $media_file_dir . "/' AND sf_name='" . $media_file_name . "' AND fk_sl_id='" . $this->GetSLID() . "'";
- $file_manager_media->GetFiles( $query_more );
- if( $file_manager_media->count > 0 )
- {
- $related_file_ids[] = $file_manager_media->data["sf_sf_id"][0];
- }
- else
- {
- // LOG ERROR : mediafile is not indexed in a7pro
- $this->WriteToLog('MediaFile not indexed on A7PRO : file_path="'.$media_file_dir.'",file_name="'.$media_file_name.'"');
- }
- }
- // //GET the PageFiles
- // $result_pagefile = $this->query_mssql("SELECT * FROM [" . $this->GetDBName() . "].[dbo].[PageFile]
- // WHERE PublicationDate='" . $article->PublicationDate . "' AND PublicationId='" . $article->PublicationId . "' AND PageNb='" . $article->PageNb . "'" );
- //
- // while ( $article_pagefile = $this->fetch_mssql( $result_pagefile ) )
- // {
- // $article_media_count++;
- //
- // $media_path_parts = $this->mb_pathinfo("/PageFile/" . $article_pagefile->Path );
- // $media_file_dir = $media_path_parts["dirname"]; //set the file dir
- // $media_file_name = $media_path_parts["filename"]; //set the file name
- //
- // //SELECT media file id from a7pro with filename and path
- // $file_manager_media = new FileManager();
- // $file_manager_media->members_array = array( "sf.sf_id", "sf.sf_path", "sf.sf_name", "sf.sf_parent_id", "sf.fk_sl_id" );
- // $query_more = " WHERE sf_path LIKE '%" . $media_file_dir . "/' AND sf_name='" . $media_file_name . "' AND fk_sl_id='" . $this->GetSLID() . "'";
- // $file_manager_media->GetFiles( $query_more );
- //
- // if( $file_manager_media->count > 0 )
- // {
- // $related_file_ids[] = $file_manager_media->data["sf_sf_id"][0];
- // }
- // else
- // {
- // // LOG ERROR : mediafile is not indexed in a7pro
- // $this->WriteToLog('PageFile not indexed on A7PRO : file_path="' . $media_file_dir . '",file_name="' . $media_file_name . '"');
- // }
- // }
- if( count( $related_file_ids ) > 1 )
- {
- //insert into relations table
- $file_related_obj = new FileRelated();
- $query_more = "";
- $file_related_obj->members_array = array( 'MAX(sfrf.fk_scs_files_related_counter)' );
- $file_related_obj->fields_aliase_array = array( "MAX(sfrf.fk_scs_files_related_counter)" => "max_counter" );
- $file_related_obj->GetFileRelatedData( $query_more );
- $max_counter = $file_related_obj->data[ 'max_counter' ][ 0 ] + 1;
- $result_related = $file_related_obj->UpdateFilesRelated( $max_counter, $related_file_ids );
- if( $result_related["is_error"] == 1 )
- {
- $this->WriteToLog('MediaFiles and .NPP could not be linked : file_ids="' . implode( ",", $related_file_ids) . '"' );
- }
- }
- }else{
- //LOG ERROR: .npp file not found in system_files
- $this->WriteToLog('NPP filenot indexed on A7PRO : file_path="' . $sf_path . '",file_name="' . $sf_name . '"' );
- }
- }
- }
- }
- function LinkPDFFiles()
- {
- global $tableCollab, $config;
- $file_manager_obj = new FileManager();
- $meta_data_types = new MetaDataTypes();
- $categories_obj = new Categories();
- $a7_base_dir = array();
- $this->FillSLIDS();
- $pdf_count = 0;
- $pdf_id = 0;
- {/** select total result */
- $result_total = $this->query_mssql("SELECT count(*)
- FROM [" . $this->GetDBName() . "].[dbo].[PageFile]");
- $pdfs_count = $this->fetch_mssql( $result_total );
- $total_count = $pdfs_count->computed;
- echo $total_count;
- }
- while ( $pdf_count < $total_count )
- {
- $result = $this->query_mssql("SELECT TOP 100 PageFileId ,PublicationDate,PageNb,PublicationId,Path,LastModifiedBy,LastModificationDate,PreviewImagePath FROM [" . $this->GetDBName() . "].[dbo].[PageFile] WHERE PageFileId > " . $pdf_id);
- //$result = $this->query_mssql("SELECT TOP 100 PageFileId ,PublicationDate,PageNb,PublicationId,Path,LastModifiedBy,LastModificationDate,PreviewImagePath FROM [" . $this->GetDBName() . "].[dbo].[PageFile] WHERE PageFileId =149832 ");
- while( $pdf_data = $this->fetch_mssql( $result ) )
- {
- $pdf_count++;
- $pdf_id = $pdf_data->ArticleId;
- $pub_date = date("Y-m-d", strtotime( $pdf_data->PublicationDate ) );
- $pdf_data->Path = str_replace("\\", "/", $pdf_data->Path);
- $log_string = " link pdf : " . $pdf_data->Path . " (" . $pdf_count . " of " . $total_count . ")";
- echo $log_string . "\n";
- //get the npp file id
- $sf_path = "./PageFile/" . str_replace( "\\", "/", dirname($pdf_data->Path)) . "/";
- $sf_name = basename($pdf_data->Path);
- $query_more = " WHERE sf_path='" . $sf_path . "' AND sf_name='" . $sf_name . "' AND fk_sl_id='" . $this->GetSLID() . "'";
- $file_manager_obj->members_array = array( "sf.sf_id", "sf.sf_path", "sf.sf_name", "sf.sf_parent_id", "sf.fk_sl_id" );
- $file_manager_obj->GetFiles( $query_more );
- if( $file_manager_obj->count > 0 )
- {
- $pdf_sf_id = $file_manager_obj->data["sf_sf_id"][0];
- $related_file_ids = array();
- $related_file_ids[] = $file_manager_obj->data["sf_sf_id"][0];
- $result_media = $this->query_mssql("SELECT ArticleId FROM [" . $this->GetDBName() . "].[dbo].[Article]
- WHERE PublicationDate='" . $pdf_data->PublicationDate . "' and PageNb = " . $pdf_data->PageNb );
- $article_media_count = 0;
- while ( $article_media = $this->fetch_mssql( $result_media ) )
- {
- $article_media_count++;
- $file_manager_media = new FileManager();
- $file_manager_media->members_array = array( "sf.sf_id", "sf.sf_path", "sf.sf_name", "sf.sf_parent_id", "sf.fk_sl_id" );
- $query_more = " WHERE sf_name='" . $article_media->ArticleId . ".npp" . "' AND fk_sl_id='" . $this->GetSLID() . "'";
- $file_manager_media->GetFiles( $query_more );
- if( $file_manager_media->count > 0 )
- {
- $related_file_ids[] = $file_manager_media->data["sf_sf_id"][0];
- }
- else
- {
- $this->WriteToLog('MediaFile not indexed on A7PRO : file_path="'.$media_file_dir.'",file_name="'.$media_file_name.'"');
- }
- }
- if( count( $related_file_ids ) > 1 )
- {
- //insert into relations table
- $file_related_obj = new FileRelated();
- $query_more = "";
- $file_related_obj->members_array = array( 'MAX(sfrf.fk_scs_files_related_counter)' );
- $file_related_obj->fields_aliase_array = array( "MAX(sfrf.fk_scs_files_related_counter)" => "max_counter" );
- $file_related_obj->GetFileRelatedData( $query_more );
- $max_counter = $file_related_obj->data[ 'max_counter' ][ 0 ] + 1;
- $result_related = $file_related_obj->UpdateFilesRelated( $max_counter, $related_file_ids );
- if( $result_related["is_error"] == 1 )
- {
- $this->WriteToLog('MediaFiles and .NPP could not be linked : file_ids="' . implode( ",", $related_file_ids) . '"' );
- }
- }
- }else{
- //LOG ERROR: .npp file not found in system_files
- $this->WriteToLog('NPP filenot indexed on A7PRO : file_path="' . $sf_path . '",file_name="' . $sf_name . '"' );
- }
- }
- }
- }
- function InsertArticlesMetaData( $sf_id, $article_object, $sf_path )
- {
- $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['PublicationName'], $article_object->PublicationName, $sf_path );
- $pub_date = date("Y-m-d", strtotime( $article_object->PublicationDate ) );
- $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['PublicationDate'], $pub_date, $sf_path );
- $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['PageNb'], $article_object->PageNb, $sf_path );
- $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['Caption'], $article_object->Caption, $sf_path );
- $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['Keywords'], $article_object->Keywords, $sf_path );
- $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['Description'], $article_object->Description, $sf_path );
- }
- function UpdateMediaFilesMetaData()
- {
- global $tableCollab;
- $media_file_id = 0;
- $media_file_count = 0;
- {/** select total result */
- $result_total = $this->query_mssql("SELECT count(*) FROM [" . $this->GetDBName() . "].[dbo].[MediaFile]
- LEFT JOIN [" . $this->GetDBName() . "].[dbo].[Publication] on MediaFile.PublicationId = Publication.PublicationId
- LEFT JOIN [" . $this->GetDBName() . "].[dbo].[MediaType] ON MediaType.MediaTypeId = MediaFile.MediaTypeId");
- $files_count = $this->fetch_mssql( $result_total );
- $total_count = $files_count->computed;
- }
- while ( $media_file_count < $total_count )
- {
- $result_media = $this->query_mssql("SELECT TOP 100 Publication.Name as PublicationName, MediaType.Name as MediaTypeName, MediaFile.MediaFileId, MediaFile.Path, MediaFile.PageNb
- , CAST(MediaFile.Caption AS TEXT) AS Caption, CAST(MediaFile.Keywords AS TEXT) AS Keywords, CAST(MediaFile.Description AS TEXT) AS Description FROM [" . $this->GetDBName() . "].[dbo].[MediaFile]
- LEFT JOIN [" . $this->GetDBName() . "].[dbo].[Publication] on MediaFile.PublicationId = Publication.PublicationId
- LEFT JOIN [" . $this->GetDBName() . "].[dbo].[MediaType] ON MediaType.MediaTypeId = MediaFile.MediaTypeId
- WHERE MediaFile.MediaFileId > " . $media_file_id );
- while ( $article_media = $this->fetch_mssql( $result_media ) )
- {
- $media_file_id = $article_media->MediaFileId;
- $log_string = " update media files metadata : " . $media_file_id . " (" . $media_file_count . " of " . $total_count . ")";
- echo $log_string . "\n";
- $media_file_count++;
- $media_path_parts = $this->mb_pathinfo("/" . $article_media->MediaTypeName . "/" . $article_media->Path );
- $media_file_dir = $media_path_parts["dirname"]; //set the file dir
- $media_file_name = $media_path_parts["filename"]; //set the file name
- //SELECT media file id from a7pro with filename and path
- $file_manager_media = new FileManager();
- $file_manager_media->members_array = array( "sf.sf_id", "sf.sf_path", "sf.sf_name", "sf.sf_parent_id", "sf.fk_sl_id" );
- $query_more = " WHERE sf_path LIKE '%" . $media_file_dir . "/' AND sf_name='" . $media_file_name . "' AND fk_sl_id='" . $this->GetSLID() . "'";
- $file_manager_media->GetFiles( $query_more );
- if( $file_manager_media->count > 0 )
- {
- $sf_id = $file_manager_media->data["sf_sf_id"][0];
- $tmp_delete_fcv = "delete from " . $tableCollab['file_category_blocks_values'] . " where fk_sf_id=" . $sf_id;
- $res = AdvancedConnectSql( $tmp_delete_fcv );
- $res = $this->InsertCategoryBlockValue( $sf_id, 1501, $article_media->Caption, $media_file_dir . "/" . $media_file_name );
- $res = $this->InsertCategoryBlockValue( $sf_id, 1502, $article_media->Keywords, $media_file_dir . "/" . $media_file_name );
- $res = $this->InsertCategoryBlockValue( $sf_id, 1503, $article_media->Description, $media_file_dir . "/" . $media_file_name );
- }
- else
- {
- // LOG ERROR : mediafile is not indexed in a7pro (update metadata error)
- $this->WriteToLog('Could not update MetaData, file not indexed on A7PRO : file_path="' . $media_file_dir . '",file_name="' . $media_file_name . '"' );
- }
- }
- }
- }
- function UpdatePageFilesMetaData()
- {
- $page_file_id = 0;
- $page_file_count = 0;
- {/** select total result */
- $result_total = $this->query_mssql("SELECT count(*) FROM PageFile
- LEFT JOIN Publication on PageFile.PublicationId = Publication.PublicationId");
- $files_count = $this->fetch_mssql( $result_total );
- $total_count = $files_count->computed;
- }
- while ( $page_file_count < $total_count )
- {
- $result_media = $this->query_mssql("SELECT TOP 100 Publication.Name as PublicationName, PageFile.PublicationDate, PageFile.PageFileId, Path FROM [" . $this->GetDBName() . "].[dbo].[PageFile]
- LEFT JOIN [" . $this->GetDBName() . "].[dbo].[Publication] on PageFile.PublicationId = Publication.PublicationId
- WHERE PageFile.PageFileId > " . $page_file_id );
- while ( $article_media = $this->fetch_mssql( $result_media ) )
- {
- $page_file_id = $article_media->PageFileId;
- $log_string = " update metadata : " . $page_file_id . " (" . $page_file_count . " of " . $total_count . ")";
- echo $log_string . "\n";
- $page_file_count++;
- $media_path_parts = $this->mb_pathinfo("/PageFile/" . $article_media->Path );
- $media_file_dir = $media_path_parts["dirname"]; //set the file dir
- $media_file_name = $media_path_parts["filename"]; //set the file name
- //SELECT media file id from a7pro with filename and path
- $file_manager_media = new FileManager();
- $file_manager_media->members_array = array( "sf.sf_id", "sf.sf_path", "sf.sf_name", "sf.sf_parent_id", "sf.fk_sl_id" );
- $query_more = " WHERE sf_path LIKE '%" . $media_file_dir . "/' AND sf_name='" . $media_file_name . "' AND fk_sl_id='" . $this->GetSLID() . "'";
- $file_manager_media->GetFiles( $query_more );
- if( $file_manager_media->count > 0 )
- {
- $sf_id = $file_manager_media->data["sf_sf_id"][0];
- $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['PublicationName'], $article_media->PublicationName, $media_file_dir . "/" . $media_file_name );
- $pub_date = date("Y-m-d", strtotime( $article_media->PublicationDate ) );
- $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['PublicationDate'], $pub_date, $media_file_dir . "/" . $media_file_name );
- $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['PageNb'], $article_media->PageNb, $media_file_dir . "/" . $media_file_name );
- }
- else
- {
- // LOG ERROR : mediafile is not indexed in a7pro (update metadata error)
- $this->WriteToLog('Could not update MetaData, file not indexed on A7PRO : file_path="' . $media_file_dir . '",file_name="' . $media_file_name . '"' );
- }
- }
- }
- }
- function UpdateVipFilesMetaData()
- {
- $vip_count = 0;
- $vip_id = 0;
- {/** select total result */
- $result_total = $this->query_mssql("SELECT count(*) FROM [" . $this->GetDBName() . "].[dbo].[Vip] WHERE LEN(ProfileImagePath) > 2");
- $files_count = $this->fetch_mssql( $result_total );
- $total_count = $files_count->computed;
- }
- while ( $vip_count < $total_count )
- {
- $result_media = $this->query_mssql("SELECT TOP 100
- VipId, ProfileImagePath, CAST(Name AS TEXT) AS Name, CAST(PlaceOfBirth AS TEXT) AS PlaceOfBirth, BirthDate, CAST(CurriculumVitae AS TEXT) AS CurriculumVitae, CAST(NickName AS TEXT) AS NickName FROM [" . $this->GetDBName() . "].[dbo].[Vip]
- WHERE Vip.VipId > " . $vip_id . ' AND LEN(ProfileImagePath) > 2' );
- while ( $article_media = $this->fetch_mssql( $result_media ) )
- {
- $vip_id = $article_media->VipId;
- echo "Vip ID : " . $vip_id . " (" . $vip_count . " of " . $total_count . ")" . "\n";
- $vip_count++;
- $media_path_parts = $this->mb_pathinfo("/Vip/" . $article_media->ProfileImagePath );
- $media_file_dir = $media_path_parts["dirname"]; //set the file dir
- $media_file_name = $media_path_parts["filename"]; //set the file name
- //SELECT media file id from a7pro with filename and path
- $file_manager_media = new FileManager();
- $file_manager_media->members_array = array( "sf.sf_id", "sf.sf_path", "sf.sf_name", "sf.sf_parent_id", "sf.fk_sl_id" );
- $query_more = " WHERE sf_path LIKE '%" . $media_file_dir . "/' AND sf_name='" . $media_file_name . "' AND fk_sl_id='" . $this->GetSLID() . "'";
- $file_manager_media->GetFiles( $query_more );
- if( $file_manager_media->count > 0 )
- {
- $sf_id = $file_manager_media->data["sf_sf_id"][0];
- $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['VIP_Name'], $article_media->Name, $media_file_dir . "/" . $media_file_name );
- $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['VIP_Name'], $article_media->Name, $media_file_dir . "/" . $media_file_name );
- $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['PlaceOfBirth'], $article_media->PlaceOfBirth, $media_file_dir . "/" . $media_file_name );
- $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['BirthDate'], $article_media->BirthDate, $media_file_dir . "/" . $media_file_name );
- $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['CurriculumVitae'], $article_media->CurriculumVitae, $media_file_dir . "/" . $media_file_name );
- $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['NickName'], $article_media->NickName, $media_file_dir . "/" . $media_file_name );
- }
- else
- {
- // LOG ERROR : mediafile is not indexed in a7pro (update metadata error)
- $this->WriteToLog('Could not update MetaData, file not indexed on A7PRO : file_path="' . $media_file_dir . '",file_name="' . $media_file_name . '"' );
- }
- }
- }
- }
- function InsertCategoryBlockValue( $sf_id, $category_id, $category_value, $sf_path = "" )
- {
- global $tableCollab;
- $category_value = iconv("windows-1256","UTF-8", $category_value );
- $tmp_delete_fcv = "delete from " . $tableCollab['file_category_blocks_values'] . " where fk_category_id = " . $category_id . " and fk_sf_id=" . $sf_id;
- $res = AdvancedConnectSql( $tmp_delete_fcv );
- $tmp_insert_fcv = "INSERT INTO " . $tableCollab['file_category_blocks_values'] . " (`fk_category_id`,`fcbv_value`, fk_sf_id, fcbv_creation_date, fcbv_coming_from ) VALUES (" . $category_id . ",'" . addslashes( $category_value ) . "', " . $sf_id . ", NOW(), 10 )";
- $res = AdvancedConnectSql( $tmp_insert_fcv );
- if( $res['query_error'] )
- {
- $log_string = " insert category to : " . $sf_path . " (error)";
- PrintHelper::PrintToFile( $this->GetLogFolder(), $this->GetLogFile(), date('H:i:s') . " : " . $log_string . "\n", "ab+", 2 );
- }
- else
- {
- $log_string = " insert category to : " . $sf_path . " (success)";
- }
- echo "\n" . $log_string;
- }
- function CreateNPPFiles()
- {
- global $tableCollab, $config;
- $file_manager_obj = new FileManager();
- $meta_data_types = new MetaDataTypes();
- $categories_obj = new Categories();
- $a7_base_dir = array();
- $this->FillSLIDS();
- $article_count = 0;
- $article_id = 0;
- {/** select total result */
- $result_total = $this->query_mssql("SELECT count(*)
- FROM [" . $this->GetDBName() . "].[dbo].[Article]
- left join [" . $this->GetDBName() . "].[dbo].[Publication] on Article.PublicationId = Publication.PublicationId
- left join [" . $this->GetDBName() . "].[dbo].[Category] on Article.CategoryId = Category.CategoryId
- left join [" . $this->GetDBName() . "].[dbo].[Author] on Article.AuthorId = Author.AuthorId");
- $articles_count = $this->fetch_mssql( $result_total );
- $total_count = $articles_count->computed;
- }
- while ( $article_count < $total_count )
- {
- $result = $this->query_mssql("SELECT TOP 100 Publication.Name as Publication_Name, Category.Name as Section_Name, Author.Name as Author_Name, Article.ArticleId
- , CAST(Article.Headline AS TEXT) AS Article_Headline, CAST(Article.SubHeadline AS TEXT) AS Article_SubHeadline, CAST(Article.Body AS TEXT) AS Article_Body
- , CAST(Article.Keywords AS TEXT) AS Article_Keywords, CAST(Article.Summary AS TEXT) AS Article_Summary, CAST(Article.Introduction AS TEXT) AS Article_Introduction
- , CAST(Article.Catchline AS TEXT) AS Article_Catchline
- ,Article.AuthorId as Article_AuthorId, Article.LanguageId as Article_LanguageId, Article.CountryId as Article_CountryId, Article.CategoryId as Article_CategoryId
- , Article.CreationDate as Article_CreationDate, Article.IsArchived as Article_IsArchived, Article.ArchivedBy as Article_ArchivedBy, Article.ArchiveDate as Article_ArchiveDate
- ,Article.PublicationDate as Article_PublicationDate, Article.LastModifiedBy as Article_LastModifiedBy, Article.LastModificationDate as Article_LastModificationDate
- , Article.PageNb as Article_PageNb, Article.IssueNb as Article_IssueNb, Article.PublicationId as Article_PublicationId
- ,CAST(Article.HeadlineTrimmed AS TEXT) AS Article_HeadlineTrimmed, CAST(Article.SubHeadlineTrimmed AS TEXT) AS Article_SubHeadlineTrimmed
- , CAST(Article.BodyTrimmed AS TEXT) AS Article_BodyTrimmed, CAST(Article.KeywordsTrimmed AS TEXT) AS Article_KeywordsTrimmed, CAST(Article.SummaryTrimmed AS TEXT) AS Article_SummaryTrimmed
- ,CAST(Article.IntroductionTrimmed AS TEXT) AS Article_IntroductionTrimmed, CAST(Article.CatchlineTrimmed AS TEXT) AS Article_CatchlineTrimmed
- FROM [" . $this->GetDBName() . "].[dbo].[Article]
- left join [" . $this->GetDBName() . "].[dbo].[Publication] on Article.PublicationId = Publication.PublicationId
- left join [" . $this->GetDBName() . "].[dbo].[Category] on Article.CategoryId = Category.CategoryId
- left join [" . $this->GetDBName() . "].[dbo].[Author] on Article.AuthorId = Author.AuthorId
- WHERE Article.ArticleId > " . $article_id );
- while( $article = $this->fetch_mssql( $result ) )
- {
- $article_count++;
- $article_id = $article->ArticleId;
- $pub_date = date("Y-m-d", strtotime( $article->Article_PublicationDate ) );
- $article->Publication_Name = iconv("windows-1256","UTF-8", $article->Publication_Name );
- $article->Section_Name = iconv("windows-1256","UTF-8", $article->Section_Name );
- $article->Author_Name = iconv("windows-1256","UTF-8", $article->Author_Name );
- $article->Article_Headline = iconv("windows-1256","UTF-8", $article->Article_Headline );
- $article->Article_Introduction = iconv("windows-1256","UTF-8", $article->Article_Introduction );
- $article->Article_Summary = iconv("windows-1256","UTF-8", $article->Article_Summary );
- $article->Article_Body = iconv("windows-1256","UTF-8", $article->Article_Body );
- $destination_path = "./articles-easynews/" . date("Y", strtotime( $article->Article_PublicationDate ) ) . "/" . date("m", strtotime( $article->Article_PublicationDate ) ) . "/" . date("d", strtotime( $article->Article_PublicationDate ) ) . "/";
- $action_result = $this->CreateFolderIfNotExist( $destination_path );
- $not_related_dir_id = $action_result['directory_id'];
- $file_info = array();
- $file_info['dir_id'] = $not_related_dir_id;
- $file_info['dir_path'] = $destination_path;
- $file_info['file_name'] = $article_id;
- $file_info['issue_date'] = $pub_date;
- $file_info['publication'] = "Peninsula";
- $file_info['section'] = $article->Section_Name;
- $file_info['page_number'] = $article->Article_PageNb;
- $file_info['author'] = $article->Author_Name;
- $file_info['word_size'] = 0;
- $file_info['title_content'] = $article->Article_Headline;
- $file_info['title_x_coordinates'] = "";
- $file_info['title_y_coordinates'] = "";
- $file_info['subtitle_content'] = $article->Article_Introduction;
- $file_info['subtitle_x_coordinates'] = "";
- $file_info['subtitle_y_coordinates'] = "";
- $file_info['byline_content'] = $article->Article_Summary;
- $file_info['byline_x_coordinates'] = "";
- $file_info['byline_y_coordinates'] = "";
- $file_info['body_content'] = $article->Article_Body;
- $file_info['body_x_coordinates'] = "";
- $file_info['body_y_coordinates'] = "";
- $file_info['sl_id'] = $this->GetSLID();
- $file_info['storage_path'] = $this->sl_paths[ $this->GetSLID() ];
- $file_info['user_id'] = 0;
- $action_result = $file_manager_obj->CreateNewArticle( $file_info);
- if( $action_result['error'] )
- {
- $log_string = " create file : " . $article_id . ".npp" . " (error : ".$action_result['error_msg'].") (" . $article_count . " of " . $total_count . ")";
- $maintenancelogs_obj = new MaintenanceLogsManager();
- $maintenancelogs_obj->InsertLog(MaintenanceLogsManager::MM25_ARCHIVE_MIGRATION, $log_string);
- PrintHelper::PrintToFile( $this->GetLogFolder(), $this->GetLogFile(), date('H:i:s') . " : " . $log_string . "\n", "ab+", 2 );
- }
- else
- {
- $res = $this->InsertCategoryBlockValue( $action_result['file_id'], 1001, $article->Article_IssueNb, "" );
- $log_string = " create file : " . $article_id . ".npp" . " (success) (" . $article_count . " of " . $total_count . ")";
- }
- echo "\n" . $log_string;
- }
- }
- }
- function WriteToLog( $log_string )
- {
- $maintenancelogs_obj = new MaintenanceLogsManager();
- $maintenancelogs_obj->InsertLog( MaintenanceLogsManager::MM25_ARCHIVE_MIGRATION, $log_string );
- PrintHelper::PrintToFile( $this->GetLogFolder(), $this->GetLogFile(), date( 'H:i:s' ) . " : " . $log_string . "\n", "ab+", 2 );
- }
- function CreateFolderIfNotExist( $dir_path )
- {
- $file_manager_obj = new FileManager();
- $org_dir_path = $dir_path;
- $action_result['error'] = 0;
- $dir_path = explode( "/" , $dir_path );
- $all_paths = array();
- for( $i = 0 ; $i < count( $dir_path ) - 1 ; $i++ )
- {
- /** fill path of every folder */
- $all_paths[$i] = "./";
- for( $k = 1 ; $k <= $i ; $k++ )
- {
- $all_paths[$i] .= $dir_path[ $k ] . "/";
- }
- }
- for( $i = 0 ; $i < count( $all_paths ) ; $i++ )
- {
- $full_path = DirectoryHelper::ConvertSLPathFromRelativeToFull( $all_paths[$i], $this->sl_paths[ $this->GetSLID() ] );
- $full_path = TextHelper::ConvertFromUTF8ToWIN1256( $full_path );
- if( !is_dir( $full_path ) )
- {
- $dir_path = dirname( $all_paths[$i] ) . "/";
- $dir_id = $file_manager_obj->RetrieveDirIdFromPath( $dir_path, $this->GetSLID() );
- $folder_info = array();
- $folder_info['dir_path'] = $dir_path;
- $folder_info['dir_id'] = $dir_id;
- $folder_info['folder_name'] = basename( $all_paths[$i] );
- $folder_info['sf_indexing_flag'] = 0;
- $folder_info['coming_from'] = 18;
- $folder_info['sl_id'] = $this->GetSLID();
- $folder_info['storage_path'] = $this->sl_paths[ $this->GetSLID() ];
- $result = $file_manager_obj->CreateFolder( $folder_info );
- //print_r($folder_info);
- //print_r($result);
- $action_result['directory_id'] = $result['sf_id'];
- if( $result['error'] )
- {
- $action_result['error'] = 1;
- }
- //DirectoryHelper::UpdateFolderCount( $dir_id );
- }
- else
- {
- $dir_id = $file_manager_obj->RetrieveDirIdFromPath( implode("/", $dir_path ), $this->GetSLID() );
- $action_result['directory_id'] = $dir_id;
- }
- }
- return $action_result;
- }
- function mb_pathinfo( $filepath )
- {
- $ret = array();
- preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $filepath, $m );
- if( $m[1] ) $ret['dirname'] = str_replace("\\", "/", $m[1] );
- if( $m[2] ) $ret['basename'] = $m[2];
- if( $m[5] ) $ret['extension'] = $m[5];
- if( $m[3] ) $ret['filename'] = $m[3] . "." . $m[5];
- return $ret;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement