Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.61 KB | None | 0 0
  1. <?php
  2. /************************************************************
  3. ad.host.class.php
  4. Product : Digital Asset
  5. Version : 1.0
  6. Release : 0
  7. Date Created : Fri Mar 12 16:09:28 EET 2010
  8. Developed By : Kamil Baderddine PHP Department LayoutLTD
  9. All Rights Reserved , Layout LTD COPYRIGHT 2010
  10.  
  11. Page Description :
  12.  
  13. ************************************************************/
  14.  
  15.  
  16. class EasyNewsManager extends request{
  17.  
  18. var $sl_id = null;
  19. var $kv_db_server = null;
  20. var $kv_db = null;
  21. var $kv_db_user = null;
  22. var $kv_limit = null;
  23. var $kv_type = null;
  24. var $kv_password = null;
  25. var $mssql;
  26. var $sl_paths;
  27. var $log_folder;
  28. var $log_file;
  29.  
  30. /**
  31. * Class Constructor
  32. *
  33. * @return KVManager
  34. */
  35. function EasyNewsManager ( $variable_intialization_array )
  36. {
  37. $this->SetSLID( $variable_intialization_array['sl_id'] );
  38. $this->SetDBServer( $variable_intialization_array['kv_db_server'] );
  39. $this->SetDBName( $variable_intialization_array['kv_db'] );
  40. $this->SetDBUser( $variable_intialization_array['kv_db_user'] );
  41. $this->SetLimit( $variable_intialization_array['kv_limit'] );
  42. $this->SetType( $variable_intialization_array['kv_type'] );
  43. $this->SetDBPassword( $variable_intialization_array['kv_password'] );
  44. $this->SetLogFolder( URLHelper::BuildMaintenanceLogsPath() . "archive_migration/" );
  45. $this->SetLogFile( URLHelper::BuildMaintenanceLogsFileName() );
  46.  
  47. $this->categories_ids = array();
  48. $this->categories_ids['PublicationName'] = 17;
  49. $this->categories_ids['PublicationDate'] = 21;
  50. $this->categories_ids['PageNb'] = 24;
  51. $this->categories_ids['Caption'] = 26;
  52. $this->categories_ids['Keywords'] = 2;
  53. $this->categories_ids['Description'] = 3;
  54. $this->categories_ids['VIP_Name'] = 34;
  55. $this->categories_ids['PlaceOfBirth'] = 35;
  56. $this->categories_ids['BirthDate'] = 36;
  57. $this->categories_ids['CurriculumVitae'] = 37;
  58. $this->categories_ids['NickName'] = 38;
  59.  
  60. $this->connect_mssql();
  61. }
  62.  
  63. function connect_mssql()
  64. {
  65. $conn_array = array
  66. (
  67. "UID" => $this->GetDBUser(),
  68. "PWD" => $this->GetDBPassword(),
  69. "Database" => $this->GetDBName(),
  70. "ReturnDatesAsStrings" => true,
  71. 'CharacterSet' => 'UTF-8'
  72. );
  73.  
  74. $this->mssql = mssql_connect($this->GetDBServer(), $this->GetDBUser(), $this->GetDBPassword());
  75.  
  76. if (!$this->mssql || !mssql_select_db($this->GetDBName(), $this->mssql))
  77. {
  78. die( print_r( sqlsrv_errors(), true ) );
  79. }
  80. }
  81.  
  82. function query_mssql($query)
  83. {
  84. return $result = mssql_query( $query );
  85. }
  86.  
  87. function fetch_mssql( $result )
  88. {
  89. $row = mssql_fetch_object( $result );
  90. return $row;
  91. }
  92.  
  93. /**
  94. * Set Log Folder Path
  95. *
  96. * @param Int $log_folder_path
  97. */
  98. function SetLogFolder( $log_folder_path )
  99. {
  100. $this->log_folder = $log_folder_path;
  101. }
  102.  
  103. /**
  104. * Get Log Folder Path
  105. *
  106. * @return String
  107. */
  108. function GetLogFolder()
  109. {
  110. return $this->log_folder;
  111. }
  112.  
  113. /**
  114. * Set Log File Name
  115. *
  116. * @param Int $log_file
  117. */
  118. function SetLogFile( $log_file )
  119. {
  120. $this->log_file = $log_file;
  121. }
  122.  
  123. /**
  124. * Get Log File Name
  125. *
  126. * @return String
  127. */
  128. function GetLogFile()
  129. {
  130. return $this->log_file;
  131. }
  132.  
  133. /**
  134. * Set sl_id
  135. *
  136. * @param Int $log_folder_path
  137. */
  138. function SetSLID( $sl_id )
  139. {
  140. $this->sl_id = $sl_id;
  141. }
  142.  
  143. /**
  144. * Get sl_id
  145. *
  146. * @return String
  147. */
  148. function GetSLID()
  149. {
  150. return $this->sl_id;
  151. }
  152.  
  153. /**
  154. * Set $kv_db_server
  155. *
  156. * @param Int $kv_db_server
  157. */
  158. function SetDBServer( $kv_db_server )
  159. {
  160. $this->kv_db_server = $kv_db_server;
  161. }
  162.  
  163. /**
  164. * Get kv_db_server
  165. *
  166. * @return String
  167. */
  168. function GetDBServer()
  169. {
  170. return $this->kv_db_server;
  171. }
  172.  
  173. /**
  174. * Set $kv_db
  175. *
  176. * @param Int $kv_db
  177. */
  178. function SetDBName( $kv_db )
  179. {
  180. $this->kv_db = $kv_db;
  181. }
  182.  
  183. /**
  184. * Get kv_db
  185. *
  186. * @return String
  187. */
  188. function GetDBName()
  189. {
  190. return $this->kv_db;
  191. }
  192.  
  193. /**
  194. * Set $kv_db_user
  195. *
  196. * @param Int $kv_db_user
  197. */
  198. function SetDBUser( $kv_db_user )
  199. {
  200. $this->kv_db_user = $kv_db_user;
  201. }
  202.  
  203. /**
  204. * Get $kv_db_user
  205. *
  206. * @return String
  207. */
  208. function GetDBUser()
  209. {
  210. return $this->kv_db_user;
  211. }
  212.  
  213. /**
  214. * Set $kv_limit
  215. *
  216. * @param Int $kv_limit
  217. */
  218. function SetLimit( $kv_limit )
  219. {
  220. $this->kv_limit = $kv_limit;
  221. }
  222.  
  223. /**
  224. * Get $kv_db_user
  225. *
  226. * @return String
  227. */
  228. function GetLimit()
  229. {
  230. return $this->kv_limit;
  231. }
  232.  
  233. /**
  234. * Set $kv_type
  235. *
  236. * @param Int $kv_type
  237. */
  238. function SetType( $kv_type )
  239. {
  240. $this->kv_type = $kv_type;
  241. }
  242.  
  243. /**
  244. * Get $kv_db_user
  245. *
  246. * @return String
  247. */
  248. function GetType()
  249. {
  250. return $this->kv_type;
  251. }
  252.  
  253. /**
  254. * Set $kv_password
  255. *
  256. * @param Int $kv_password
  257. */
  258. function SetDBPassword( $kv_password )
  259. {
  260. $this->kv_password = $kv_password;
  261. }
  262.  
  263. /**
  264. * Get $kv_password
  265. *
  266. * @return String
  267. */
  268. function GetDBPassword()
  269. {
  270. return $this->kv_password;
  271. }
  272.  
  273. /**
  274. * Fill storage location ids
  275. *
  276. */
  277. function FillSLIDS()
  278. {
  279. $storage_manager_obj = new StorageManager();
  280. $storage_manager_obj->members_array = array( "sl.sl_id", "sl.sl_path" );
  281. $query_more = "";
  282. $storage_manager_obj->GetStorageLocations( $query_more );
  283.  
  284. for( $i = 0 ; $i < $storage_manager_obj->count ; $i++ )
  285. {
  286. $this->SetSLPaths( $storage_manager_obj->data["sl_sl_path"][$i], $storage_manager_obj->data["sl_sl_id"][$i] );
  287. }
  288. }
  289.  
  290. /**
  291. * Set SL Paths
  292. *
  293. * @param Int $row_date
  294. */
  295. function SetSLPaths( $sl_path, $sl_id )
  296. {
  297. $this->sl_paths[ $sl_id ] = $sl_path;
  298. }
  299.  
  300.  
  301. /**
  302. * Manage KV
  303. *
  304. */
  305. function ManageKVTypes()
  306. {
  307. switch ( $this->GetType() )
  308. {
  309. case "en_create_npp_files":
  310. {
  311. echo "\n\n" . date('H:i:s') . " create npp files Launched\n\n";
  312. $this->CreateNPPFiles();
  313. echo "\n\n" . date('H:i:s') . " create npp files Finished\n\n";
  314. }
  315. break;
  316. case "en_link_files":
  317. {
  318. echo "\n\n" . date('H:i:s') . " link files Launched\n\n";
  319. $this->LinkFiles();
  320. echo "\n\n" . date('H:i:s'). " files linked, article metadata updated\n\n";
  321. }
  322. case "en_link_pdf_files":
  323. {
  324. echo "\n\n" . date('H:i:s') . " link pdf files Launched\n\n";
  325. $this->LinkPDFFiles();
  326. echo "\n\n" . date('H:i:s'). " files linked\n\n";
  327. }
  328. break;
  329. case "en_update_categories":
  330. {
  331. echo "\n\n" . date('H:i:s'). " updating MediaFiles metadata\n\n";
  332. $this->UpdateMediaFilesMetaData();
  333. echo "\n\n" . date('H:i:s'). " MediaFiles metadata update Finished\n\n";
  334.  
  335. sleep( 10000000 );
  336. echo "\n\n" . date('H:i:s'). " updating PageFiles metadata\n\n";
  337. //$this->UpdatePageFilesMetaData();
  338. echo "\n\n" . date('H:i:s'). " PageFiles metadata update Finished\n\n";
  339. }
  340. break;
  341. case "en_vip_data":
  342. {
  343. echo "\n\n" . date('H:i:s'). " updating Vip metadata\n\n";
  344. $this->UpdateVipFilesMetaData();
  345. echo "\n\n" . date('H:i:s'). " Vip metadata update Finished\n\n";
  346.  
  347. sleep( 10000000 );
  348. }
  349. break;
  350. }
  351. }
  352.  
  353. function LinkFiles()
  354. {
  355. global $tableCollab, $config;
  356.  
  357. $file_manager_obj = new FileManager();
  358. $meta_data_types = new MetaDataTypes();
  359. $categories_obj = new Categories();
  360. $a7_base_dir = array();
  361.  
  362. $this->FillSLIDS();
  363. $article_count = 0;
  364. $article_id = 0;
  365.  
  366. {/** select total result */
  367. $result_total = $this->query_mssql("SELECT count(*)
  368. FROM [" . $this->GetDBName() . "].[dbo].[Article]
  369. left join [" . $this->GetDBName() . "].[dbo].[Publication] on Article.PublicationId = Publication.PublicationId
  370. left join [" . $this->GetDBName() . "].[dbo].[Category] on Article.CategoryId = Category.CategoryId
  371. left join [" . $this->GetDBName() . "].[dbo].[Author] on Article.AuthorId = Author.AuthorId");
  372.  
  373. $articles_count = $this->fetch_mssql( $result_total );
  374.  
  375. $total_count = $articles_count->computed;
  376. echo $total_count;
  377. }
  378.  
  379. while ( $article_count < $total_count )
  380. {
  381. $result = $this->query_mssql("SELECT TOP 100 Publication.Name as Publication_Name, Category.Name as Section_Name, Author.Name as Author_Name, Article.ArticleId
  382. , Article.PublicationDate, Article.PublicationId, Article.PageNb
  383. FROM [" . $this->GetDBName() . "].[dbo].[Article]
  384. left join [" . $this->GetDBName() . "].[dbo].[Publication] on Article.PublicationId = Publication.PublicationId
  385. left join [" . $this->GetDBName() . "].[dbo].[Category] on Article.CategoryId = Category.CategoryId
  386. left join [" . $this->GetDBName() . "].[dbo].[Author] on Article.AuthorId = Author.AuthorId
  387. WHERE Article.ArticleId > " . $article_id);
  388.  
  389. while( $article = $this->fetch_mssql( $result ) )
  390. {
  391. $article_count++;
  392. $article_id = $article->ArticleId;
  393. $pub_date = date("Y-m-d", strtotime( $article->PublicationDate ) );
  394.  
  395. $log_string = " link article : " . $article_id . ".npp" . " (" . $article_count . " of " . $total_count . ")";
  396. echo $log_string . "\n";
  397.  
  398. //get the npp file id
  399. $sf_path = "./articles/" . str_replace( "-", "/", $pub_date ) . "/" . ( !empty( $article->PublicationId ) ? $article->PublicationId : "no_publication" ) . "/";
  400. $sf_name = $article_id . ".npp";
  401.  
  402. $query_more = " WHERE sf_path='" . $sf_path . "' AND sf_name='" . $sf_name . "' AND fk_sl_id='" . $this->GetSLID() . "'";
  403. $file_manager_obj->members_array = array( "sf.sf_id", "sf.sf_path", "sf.sf_name", "sf.sf_parent_id", "sf.fk_sl_id" );
  404. $file_manager_obj->GetFiles( $query_more );
  405.  
  406. if( $file_manager_obj->count > 0 )
  407. {
  408. $npp_sf_id = $file_manager_obj->data["sf_sf_id"][0];
  409. $related_file_ids = array();
  410. $related_file_ids[] = $file_manager_obj->data["sf_sf_id"][0];
  411. //get articles media files
  412.  
  413. $result_media = $this->query_mssql("SELECT MediaType.Name as MediaTypeName, CAST(MediaFile.Path AS TEXT) AS MediaFilePath FROM [" . $this->GetDBName() . "].[dbo].[MediaFile]
  414. LEFT JOIN [" . $this->GetDBName() . "].[dbo].[MediaType] ON MediaType.MediaTypeId = MediaFile.MediaTypeId
  415. WHERE MediaFile.ArticleId = " . $article_id );
  416. $article_media_count = 0;
  417. while ( $article_media = $this->fetch_mssql( $result_media ) )
  418. {
  419. $article_media_count++;
  420.  
  421. $media_path_parts = $this->mb_pathinfo( "/" . $article_media->MediaFilePath );
  422. $media_file_dir = $media_path_parts["dirname"]; //set the file dir
  423. $media_file_name = $media_path_parts["filename"]; //set the file name
  424.  
  425. //SELECT media file id from a7pro with filename and path
  426. $file_manager_media = new FileManager();
  427. $file_manager_media->members_array = array( "sf.sf_id", "sf.sf_path", "sf.sf_name", "sf.sf_parent_id", "sf.fk_sl_id" );
  428. $query_more = " WHERE sf_path LIKE '%" . $media_file_dir . "/' AND sf_name='" . $media_file_name . "' AND fk_sl_id='" . $this->GetSLID() . "'";
  429. $file_manager_media->GetFiles( $query_more );
  430.  
  431. if( $file_manager_media->count > 0 )
  432. {
  433. $related_file_ids[] = $file_manager_media->data["sf_sf_id"][0];
  434. }
  435. else
  436. {
  437. // LOG ERROR : mediafile is not indexed in a7pro
  438. $this->WriteToLog('MediaFile not indexed on A7PRO : file_path="'.$media_file_dir.'",file_name="'.$media_file_name.'"');
  439. }
  440. }
  441.  
  442. // //GET the PageFiles
  443. // $result_pagefile = $this->query_mssql("SELECT * FROM [" . $this->GetDBName() . "].[dbo].[PageFile]
  444. // WHERE PublicationDate='" . $article->PublicationDate . "' AND PublicationId='" . $article->PublicationId . "' AND PageNb='" . $article->PageNb . "'" );
  445. //
  446. // while ( $article_pagefile = $this->fetch_mssql( $result_pagefile ) )
  447. // {
  448. // $article_media_count++;
  449. //
  450. // $media_path_parts = $this->mb_pathinfo("/PageFile/" . $article_pagefile->Path );
  451. // $media_file_dir = $media_path_parts["dirname"]; //set the file dir
  452. // $media_file_name = $media_path_parts["filename"]; //set the file name
  453. //
  454. // //SELECT media file id from a7pro with filename and path
  455. // $file_manager_media = new FileManager();
  456. // $file_manager_media->members_array = array( "sf.sf_id", "sf.sf_path", "sf.sf_name", "sf.sf_parent_id", "sf.fk_sl_id" );
  457. // $query_more = " WHERE sf_path LIKE '%" . $media_file_dir . "/' AND sf_name='" . $media_file_name . "' AND fk_sl_id='" . $this->GetSLID() . "'";
  458. // $file_manager_media->GetFiles( $query_more );
  459. //
  460. // if( $file_manager_media->count > 0 )
  461. // {
  462. // $related_file_ids[] = $file_manager_media->data["sf_sf_id"][0];
  463. // }
  464. // else
  465. // {
  466. // // LOG ERROR : mediafile is not indexed in a7pro
  467. // $this->WriteToLog('PageFile not indexed on A7PRO : file_path="' . $media_file_dir . '",file_name="' . $media_file_name . '"');
  468. // }
  469. // }
  470.  
  471. if( count( $related_file_ids ) > 1 )
  472. {
  473. //insert into relations table
  474. $file_related_obj = new FileRelated();
  475. $query_more = "";
  476. $file_related_obj->members_array = array( 'MAX(sfrf.fk_scs_files_related_counter)' );
  477. $file_related_obj->fields_aliase_array = array( "MAX(sfrf.fk_scs_files_related_counter)" => "max_counter" );
  478. $file_related_obj->GetFileRelatedData( $query_more );
  479.  
  480. $max_counter = $file_related_obj->data[ 'max_counter' ][ 0 ] + 1;
  481. $result_related = $file_related_obj->UpdateFilesRelated( $max_counter, $related_file_ids );
  482.  
  483. if( $result_related["is_error"] == 1 )
  484. {
  485. $this->WriteToLog('MediaFiles and .NPP could not be linked : file_ids="' . implode( ",", $related_file_ids) . '"' );
  486. }
  487. }
  488.  
  489. }else{
  490. //LOG ERROR: .npp file not found in system_files
  491. $this->WriteToLog('NPP filenot indexed on A7PRO : file_path="' . $sf_path . '",file_name="' . $sf_name . '"' );
  492. }
  493. }
  494. }
  495. }
  496.  
  497. function LinkPDFFiles()
  498. {
  499. global $tableCollab, $config;
  500.  
  501. $file_manager_obj = new FileManager();
  502. $meta_data_types = new MetaDataTypes();
  503. $categories_obj = new Categories();
  504. $a7_base_dir = array();
  505.  
  506. $this->FillSLIDS();
  507. $pdf_count = 0;
  508. $pdf_id = 0;
  509.  
  510. {/** select total result */
  511. $result_total = $this->query_mssql("SELECT count(*)
  512. FROM [" . $this->GetDBName() . "].[dbo].[PageFile]");
  513.  
  514. $pdfs_count = $this->fetch_mssql( $result_total );
  515.  
  516. $total_count = $pdfs_count->computed;
  517. echo $total_count;
  518. }
  519.  
  520. while ( $pdf_count < $total_count )
  521. {
  522. $result = $this->query_mssql("SELECT TOP 100 PageFileId ,PublicationDate,PageNb,PublicationId,Path,LastModifiedBy,LastModificationDate,PreviewImagePath FROM [" . $this->GetDBName() . "].[dbo].[PageFile] WHERE PageFileId > " . $pdf_id);
  523. //$result = $this->query_mssql("SELECT TOP 100 PageFileId ,PublicationDate,PageNb,PublicationId,Path,LastModifiedBy,LastModificationDate,PreviewImagePath FROM [" . $this->GetDBName() . "].[dbo].[PageFile] WHERE PageFileId =149832 ");
  524.  
  525. while( $pdf_data = $this->fetch_mssql( $result ) )
  526. {
  527. $pdf_count++;
  528. $pdf_id = $pdf_data->ArticleId;
  529. $pub_date = date("Y-m-d", strtotime( $pdf_data->PublicationDate ) );
  530. $pdf_data->Path = str_replace("\\", "/", $pdf_data->Path);
  531. $log_string = " link pdf : " . $pdf_data->Path . " (" . $pdf_count . " of " . $total_count . ")";
  532. echo $log_string . "\n";
  533.  
  534. //get the npp file id
  535. $sf_path = "./PageFile/" . str_replace( "\\", "/", dirname($pdf_data->Path)) . "/";
  536. $sf_name = basename($pdf_data->Path);
  537.  
  538. $query_more = " WHERE sf_path='" . $sf_path . "' AND sf_name='" . $sf_name . "' AND fk_sl_id='" . $this->GetSLID() . "'";
  539. $file_manager_obj->members_array = array( "sf.sf_id", "sf.sf_path", "sf.sf_name", "sf.sf_parent_id", "sf.fk_sl_id" );
  540. $file_manager_obj->GetFiles( $query_more );
  541.  
  542. if( $file_manager_obj->count > 0 )
  543. {
  544. $pdf_sf_id = $file_manager_obj->data["sf_sf_id"][0];
  545. $related_file_ids = array();
  546. $related_file_ids[] = $file_manager_obj->data["sf_sf_id"][0];
  547.  
  548. $result_media = $this->query_mssql("SELECT ArticleId FROM [" . $this->GetDBName() . "].[dbo].[Article]
  549. WHERE PublicationDate='" . $pdf_data->PublicationDate . "' and PageNb = " . $pdf_data->PageNb );
  550. $article_media_count = 0;
  551. while ( $article_media = $this->fetch_mssql( $result_media ) )
  552. {
  553. $article_media_count++;
  554.  
  555. $file_manager_media = new FileManager();
  556. $file_manager_media->members_array = array( "sf.sf_id", "sf.sf_path", "sf.sf_name", "sf.sf_parent_id", "sf.fk_sl_id" );
  557. $query_more = " WHERE sf_name='" . $article_media->ArticleId . ".npp" . "' AND fk_sl_id='" . $this->GetSLID() . "'";
  558. $file_manager_media->GetFiles( $query_more );
  559.  
  560. if( $file_manager_media->count > 0 )
  561. {
  562. $related_file_ids[] = $file_manager_media->data["sf_sf_id"][0];
  563. }
  564. else
  565. {
  566. $this->WriteToLog('MediaFile not indexed on A7PRO : file_path="'.$media_file_dir.'",file_name="'.$media_file_name.'"');
  567. }
  568. }
  569.  
  570. if( count( $related_file_ids ) > 1 )
  571. {
  572. //insert into relations table
  573. $file_related_obj = new FileRelated();
  574. $query_more = "";
  575. $file_related_obj->members_array = array( 'MAX(sfrf.fk_scs_files_related_counter)' );
  576. $file_related_obj->fields_aliase_array = array( "MAX(sfrf.fk_scs_files_related_counter)" => "max_counter" );
  577. $file_related_obj->GetFileRelatedData( $query_more );
  578.  
  579. $max_counter = $file_related_obj->data[ 'max_counter' ][ 0 ] + 1;
  580. $result_related = $file_related_obj->UpdateFilesRelated( $max_counter, $related_file_ids );
  581.  
  582. if( $result_related["is_error"] == 1 )
  583. {
  584. $this->WriteToLog('MediaFiles and .NPP could not be linked : file_ids="' . implode( ",", $related_file_ids) . '"' );
  585. }
  586. }
  587.  
  588. }else{
  589. //LOG ERROR: .npp file not found in system_files
  590. $this->WriteToLog('NPP filenot indexed on A7PRO : file_path="' . $sf_path . '",file_name="' . $sf_name . '"' );
  591. }
  592. }
  593. }
  594. }
  595.  
  596. function InsertArticlesMetaData( $sf_id, $article_object, $sf_path )
  597. {
  598. $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['PublicationName'], $article_object->PublicationName, $sf_path );
  599. $pub_date = date("Y-m-d", strtotime( $article_object->PublicationDate ) );
  600. $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['PublicationDate'], $pub_date, $sf_path );
  601. $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['PageNb'], $article_object->PageNb, $sf_path );
  602. $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['Caption'], $article_object->Caption, $sf_path );
  603. $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['Keywords'], $article_object->Keywords, $sf_path );
  604. $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['Description'], $article_object->Description, $sf_path );
  605. }
  606.  
  607.  
  608. function UpdateMediaFilesMetaData()
  609. {
  610. global $tableCollab;
  611.  
  612. $media_file_id = 0;
  613. $media_file_count = 0;
  614.  
  615. {/** select total result */
  616. $result_total = $this->query_mssql("SELECT count(*) FROM [" . $this->GetDBName() . "].[dbo].[MediaFile]
  617. LEFT JOIN [" . $this->GetDBName() . "].[dbo].[Publication] on MediaFile.PublicationId = Publication.PublicationId
  618. LEFT JOIN [" . $this->GetDBName() . "].[dbo].[MediaType] ON MediaType.MediaTypeId = MediaFile.MediaTypeId");
  619.  
  620. $files_count = $this->fetch_mssql( $result_total );
  621.  
  622. $total_count = $files_count->computed;
  623. }
  624.  
  625. while ( $media_file_count < $total_count )
  626. {
  627. $result_media = $this->query_mssql("SELECT TOP 100 Publication.Name as PublicationName, MediaType.Name as MediaTypeName, MediaFile.MediaFileId, MediaFile.Path, MediaFile.PageNb
  628. , 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]
  629. LEFT JOIN [" . $this->GetDBName() . "].[dbo].[Publication] on MediaFile.PublicationId = Publication.PublicationId
  630. LEFT JOIN [" . $this->GetDBName() . "].[dbo].[MediaType] ON MediaType.MediaTypeId = MediaFile.MediaTypeId
  631. WHERE MediaFile.MediaFileId > " . $media_file_id );
  632.  
  633. while ( $article_media = $this->fetch_mssql( $result_media ) )
  634. {
  635. $media_file_id = $article_media->MediaFileId;
  636.  
  637. $log_string = " update media files metadata : " . $media_file_id . " (" . $media_file_count . " of " . $total_count . ")";
  638. echo $log_string . "\n";
  639.  
  640. $media_file_count++;
  641.  
  642. $media_path_parts = $this->mb_pathinfo("/" . $article_media->MediaTypeName . "/" . $article_media->Path );
  643. $media_file_dir = $media_path_parts["dirname"]; //set the file dir
  644. $media_file_name = $media_path_parts["filename"]; //set the file name
  645.  
  646. //SELECT media file id from a7pro with filename and path
  647. $file_manager_media = new FileManager();
  648. $file_manager_media->members_array = array( "sf.sf_id", "sf.sf_path", "sf.sf_name", "sf.sf_parent_id", "sf.fk_sl_id" );
  649. $query_more = " WHERE sf_path LIKE '%" . $media_file_dir . "/' AND sf_name='" . $media_file_name . "' AND fk_sl_id='" . $this->GetSLID() . "'";
  650. $file_manager_media->GetFiles( $query_more );
  651.  
  652. if( $file_manager_media->count > 0 )
  653. {
  654. $sf_id = $file_manager_media->data["sf_sf_id"][0];
  655.  
  656. $tmp_delete_fcv = "delete from " . $tableCollab['file_category_blocks_values'] . " where fk_sf_id=" . $sf_id;
  657. $res = AdvancedConnectSql( $tmp_delete_fcv );
  658.  
  659. $res = $this->InsertCategoryBlockValue( $sf_id, 1501, $article_media->Caption, $media_file_dir . "/" . $media_file_name );
  660. $res = $this->InsertCategoryBlockValue( $sf_id, 1502, $article_media->Keywords, $media_file_dir . "/" . $media_file_name );
  661. $res = $this->InsertCategoryBlockValue( $sf_id, 1503, $article_media->Description, $media_file_dir . "/" . $media_file_name );
  662. }
  663. else
  664. {
  665. // LOG ERROR : mediafile is not indexed in a7pro (update metadata error)
  666. $this->WriteToLog('Could not update MetaData, file not indexed on A7PRO : file_path="' . $media_file_dir . '",file_name="' . $media_file_name . '"' );
  667. }
  668. }
  669. }
  670. }
  671.  
  672. function UpdatePageFilesMetaData()
  673. {
  674. $page_file_id = 0;
  675. $page_file_count = 0;
  676.  
  677. {/** select total result */
  678. $result_total = $this->query_mssql("SELECT count(*) FROM PageFile
  679. LEFT JOIN Publication on PageFile.PublicationId = Publication.PublicationId");
  680.  
  681. $files_count = $this->fetch_mssql( $result_total );
  682.  
  683. $total_count = $files_count->computed;
  684. }
  685.  
  686. while ( $page_file_count < $total_count )
  687. {
  688. $result_media = $this->query_mssql("SELECT TOP 100 Publication.Name as PublicationName, PageFile.PublicationDate, PageFile.PageFileId, Path FROM [" . $this->GetDBName() . "].[dbo].[PageFile]
  689. LEFT JOIN [" . $this->GetDBName() . "].[dbo].[Publication] on PageFile.PublicationId = Publication.PublicationId
  690. WHERE PageFile.PageFileId > " . $page_file_id );
  691.  
  692. while ( $article_media = $this->fetch_mssql( $result_media ) )
  693. {
  694. $page_file_id = $article_media->PageFileId;
  695.  
  696. $log_string = " update metadata : " . $page_file_id . " (" . $page_file_count . " of " . $total_count . ")";
  697. echo $log_string . "\n";
  698.  
  699. $page_file_count++;
  700.  
  701. $media_path_parts = $this->mb_pathinfo("/PageFile/" . $article_media->Path );
  702. $media_file_dir = $media_path_parts["dirname"]; //set the file dir
  703. $media_file_name = $media_path_parts["filename"]; //set the file name
  704.  
  705. //SELECT media file id from a7pro with filename and path
  706. $file_manager_media = new FileManager();
  707. $file_manager_media->members_array = array( "sf.sf_id", "sf.sf_path", "sf.sf_name", "sf.sf_parent_id", "sf.fk_sl_id" );
  708. $query_more = " WHERE sf_path LIKE '%" . $media_file_dir . "/' AND sf_name='" . $media_file_name . "' AND fk_sl_id='" . $this->GetSLID() . "'";
  709. $file_manager_media->GetFiles( $query_more );
  710.  
  711. if( $file_manager_media->count > 0 )
  712. {
  713. $sf_id = $file_manager_media->data["sf_sf_id"][0];
  714.  
  715. $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['PublicationName'], $article_media->PublicationName, $media_file_dir . "/" . $media_file_name );
  716.  
  717. $pub_date = date("Y-m-d", strtotime( $article_media->PublicationDate ) );
  718.  
  719. $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['PublicationDate'], $pub_date, $media_file_dir . "/" . $media_file_name );
  720. $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['PageNb'], $article_media->PageNb, $media_file_dir . "/" . $media_file_name );
  721. }
  722. else
  723. {
  724. // LOG ERROR : mediafile is not indexed in a7pro (update metadata error)
  725. $this->WriteToLog('Could not update MetaData, file not indexed on A7PRO : file_path="' . $media_file_dir . '",file_name="' . $media_file_name . '"' );
  726. }
  727. }
  728. }
  729. }
  730.  
  731. function UpdateVipFilesMetaData()
  732. {
  733. $vip_count = 0;
  734. $vip_id = 0;
  735.  
  736. {/** select total result */
  737. $result_total = $this->query_mssql("SELECT count(*) FROM [" . $this->GetDBName() . "].[dbo].[Vip] WHERE LEN(ProfileImagePath) > 2");
  738.  
  739. $files_count = $this->fetch_mssql( $result_total );
  740.  
  741. $total_count = $files_count->computed;
  742. }
  743.  
  744. while ( $vip_count < $total_count )
  745. {
  746. $result_media = $this->query_mssql("SELECT TOP 100
  747. 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]
  748. WHERE Vip.VipId > " . $vip_id . ' AND LEN(ProfileImagePath) > 2' );
  749.  
  750. while ( $article_media = $this->fetch_mssql( $result_media ) )
  751. {
  752. $vip_id = $article_media->VipId;
  753. echo "Vip ID : " . $vip_id . " (" . $vip_count . " of " . $total_count . ")" . "\n";
  754. $vip_count++;
  755.  
  756. $media_path_parts = $this->mb_pathinfo("/Vip/" . $article_media->ProfileImagePath );
  757. $media_file_dir = $media_path_parts["dirname"]; //set the file dir
  758. $media_file_name = $media_path_parts["filename"]; //set the file name
  759.  
  760. //SELECT media file id from a7pro with filename and path
  761. $file_manager_media = new FileManager();
  762. $file_manager_media->members_array = array( "sf.sf_id", "sf.sf_path", "sf.sf_name", "sf.sf_parent_id", "sf.fk_sl_id" );
  763. $query_more = " WHERE sf_path LIKE '%" . $media_file_dir . "/' AND sf_name='" . $media_file_name . "' AND fk_sl_id='" . $this->GetSLID() . "'";
  764. $file_manager_media->GetFiles( $query_more );
  765.  
  766. if( $file_manager_media->count > 0 )
  767. {
  768. $sf_id = $file_manager_media->data["sf_sf_id"][0];
  769.  
  770. $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['VIP_Name'], $article_media->Name, $media_file_dir . "/" . $media_file_name );
  771. $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['VIP_Name'], $article_media->Name, $media_file_dir . "/" . $media_file_name );
  772. $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['PlaceOfBirth'], $article_media->PlaceOfBirth, $media_file_dir . "/" . $media_file_name );
  773. $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['BirthDate'], $article_media->BirthDate, $media_file_dir . "/" . $media_file_name );
  774. $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['CurriculumVitae'], $article_media->CurriculumVitae, $media_file_dir . "/" . $media_file_name );
  775. $res = $this->InsertCategoryBlockValue( $sf_id, $this->categories_ids['NickName'], $article_media->NickName, $media_file_dir . "/" . $media_file_name );
  776. }
  777. else
  778. {
  779. // LOG ERROR : mediafile is not indexed in a7pro (update metadata error)
  780. $this->WriteToLog('Could not update MetaData, file not indexed on A7PRO : file_path="' . $media_file_dir . '",file_name="' . $media_file_name . '"' );
  781. }
  782. }
  783. }
  784. }
  785.  
  786. function InsertCategoryBlockValue( $sf_id, $category_id, $category_value, $sf_path = "" )
  787. {
  788. global $tableCollab;
  789.  
  790. $category_value = iconv("windows-1256","UTF-8", $category_value );
  791.  
  792. $tmp_delete_fcv = "delete from " . $tableCollab['file_category_blocks_values'] . " where fk_category_id = " . $category_id . " and fk_sf_id=" . $sf_id;
  793.  
  794. $res = AdvancedConnectSql( $tmp_delete_fcv );
  795.  
  796. $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 )";
  797. $res = AdvancedConnectSql( $tmp_insert_fcv );
  798.  
  799. if( $res['query_error'] )
  800. {
  801. $log_string = " insert category to : " . $sf_path . " (error)";
  802. PrintHelper::PrintToFile( $this->GetLogFolder(), $this->GetLogFile(), date('H:i:s') . " : " . $log_string . "\n", "ab+", 2 );
  803. }
  804. else
  805. {
  806. $log_string = " insert category to : " . $sf_path . " (success)";
  807. }
  808.  
  809. echo "\n" . $log_string;
  810. }
  811.  
  812. function CreateNPPFiles()
  813. {
  814. global $tableCollab, $config;
  815.  
  816. $file_manager_obj = new FileManager();
  817. $meta_data_types = new MetaDataTypes();
  818. $categories_obj = new Categories();
  819. $a7_base_dir = array();
  820.  
  821. $this->FillSLIDS();
  822.  
  823. $article_count = 0;
  824. $article_id = 0;
  825.  
  826. {/** select total result */
  827. $result_total = $this->query_mssql("SELECT count(*)
  828. FROM [" . $this->GetDBName() . "].[dbo].[Article]
  829. left join [" . $this->GetDBName() . "].[dbo].[Publication] on Article.PublicationId = Publication.PublicationId
  830. left join [" . $this->GetDBName() . "].[dbo].[Category] on Article.CategoryId = Category.CategoryId
  831. left join [" . $this->GetDBName() . "].[dbo].[Author] on Article.AuthorId = Author.AuthorId");
  832.  
  833. $articles_count = $this->fetch_mssql( $result_total );
  834.  
  835. $total_count = $articles_count->computed;
  836. }
  837.  
  838. while ( $article_count < $total_count )
  839. {
  840. $result = $this->query_mssql("SELECT TOP 100 Publication.Name as Publication_Name, Category.Name as Section_Name, Author.Name as Author_Name, Article.ArticleId
  841. , CAST(Article.Headline AS TEXT) AS Article_Headline, CAST(Article.SubHeadline AS TEXT) AS Article_SubHeadline, CAST(Article.Body AS TEXT) AS Article_Body
  842. , CAST(Article.Keywords AS TEXT) AS Article_Keywords, CAST(Article.Summary AS TEXT) AS Article_Summary, CAST(Article.Introduction AS TEXT) AS Article_Introduction
  843. , CAST(Article.Catchline AS TEXT) AS Article_Catchline
  844. ,Article.AuthorId as Article_AuthorId, Article.LanguageId as Article_LanguageId, Article.CountryId as Article_CountryId, Article.CategoryId as Article_CategoryId
  845. , Article.CreationDate as Article_CreationDate, Article.IsArchived as Article_IsArchived, Article.ArchivedBy as Article_ArchivedBy, Article.ArchiveDate as Article_ArchiveDate
  846. ,Article.PublicationDate as Article_PublicationDate, Article.LastModifiedBy as Article_LastModifiedBy, Article.LastModificationDate as Article_LastModificationDate
  847. , Article.PageNb as Article_PageNb, Article.IssueNb as Article_IssueNb, Article.PublicationId as Article_PublicationId
  848. ,CAST(Article.HeadlineTrimmed AS TEXT) AS Article_HeadlineTrimmed, CAST(Article.SubHeadlineTrimmed AS TEXT) AS Article_SubHeadlineTrimmed
  849. , CAST(Article.BodyTrimmed AS TEXT) AS Article_BodyTrimmed, CAST(Article.KeywordsTrimmed AS TEXT) AS Article_KeywordsTrimmed, CAST(Article.SummaryTrimmed AS TEXT) AS Article_SummaryTrimmed
  850. ,CAST(Article.IntroductionTrimmed AS TEXT) AS Article_IntroductionTrimmed, CAST(Article.CatchlineTrimmed AS TEXT) AS Article_CatchlineTrimmed
  851. FROM [" . $this->GetDBName() . "].[dbo].[Article]
  852. left join [" . $this->GetDBName() . "].[dbo].[Publication] on Article.PublicationId = Publication.PublicationId
  853. left join [" . $this->GetDBName() . "].[dbo].[Category] on Article.CategoryId = Category.CategoryId
  854. left join [" . $this->GetDBName() . "].[dbo].[Author] on Article.AuthorId = Author.AuthorId
  855. WHERE Article.ArticleId > " . $article_id );
  856.  
  857. while( $article = $this->fetch_mssql( $result ) )
  858. {
  859. $article_count++;
  860.  
  861. $article_id = $article->ArticleId;
  862. $pub_date = date("Y-m-d", strtotime( $article->Article_PublicationDate ) );
  863.  
  864. $article->Publication_Name = iconv("windows-1256","UTF-8", $article->Publication_Name );
  865. $article->Section_Name = iconv("windows-1256","UTF-8", $article->Section_Name );
  866. $article->Author_Name = iconv("windows-1256","UTF-8", $article->Author_Name );
  867. $article->Article_Headline = iconv("windows-1256","UTF-8", $article->Article_Headline );
  868. $article->Article_Introduction = iconv("windows-1256","UTF-8", $article->Article_Introduction );
  869. $article->Article_Summary = iconv("windows-1256","UTF-8", $article->Article_Summary );
  870. $article->Article_Body = iconv("windows-1256","UTF-8", $article->Article_Body );
  871.  
  872. $destination_path = "./articles-easynews/" . date("Y", strtotime( $article->Article_PublicationDate ) ) . "/" . date("m", strtotime( $article->Article_PublicationDate ) ) . "/" . date("d", strtotime( $article->Article_PublicationDate ) ) . "/";
  873.  
  874. $action_result = $this->CreateFolderIfNotExist( $destination_path );
  875.  
  876. $not_related_dir_id = $action_result['directory_id'];
  877.  
  878. $file_info = array();
  879. $file_info['dir_id'] = $not_related_dir_id;
  880. $file_info['dir_path'] = $destination_path;
  881. $file_info['file_name'] = $article_id;
  882. $file_info['issue_date'] = $pub_date;
  883. $file_info['publication'] = "Peninsula";
  884. $file_info['section'] = $article->Section_Name;
  885. $file_info['page_number'] = $article->Article_PageNb;
  886. $file_info['author'] = $article->Author_Name;
  887. $file_info['word_size'] = 0;
  888. $file_info['title_content'] = $article->Article_Headline;
  889. $file_info['title_x_coordinates'] = "";
  890. $file_info['title_y_coordinates'] = "";
  891. $file_info['subtitle_content'] = $article->Article_Introduction;
  892. $file_info['subtitle_x_coordinates'] = "";
  893. $file_info['subtitle_y_coordinates'] = "";
  894. $file_info['byline_content'] = $article->Article_Summary;
  895. $file_info['byline_x_coordinates'] = "";
  896. $file_info['byline_y_coordinates'] = "";
  897. $file_info['body_content'] = $article->Article_Body;
  898. $file_info['body_x_coordinates'] = "";
  899. $file_info['body_y_coordinates'] = "";
  900. $file_info['sl_id'] = $this->GetSLID();
  901. $file_info['storage_path'] = $this->sl_paths[ $this->GetSLID() ];
  902. $file_info['user_id'] = 0;
  903.  
  904. $action_result = $file_manager_obj->CreateNewArticle( $file_info);
  905.  
  906.  
  907. if( $action_result['error'] )
  908. {
  909. $log_string = " create file : " . $article_id . ".npp" . " (error : ".$action_result['error_msg'].") (" . $article_count . " of " . $total_count . ")";
  910. $maintenancelogs_obj = new MaintenanceLogsManager();
  911. $maintenancelogs_obj->InsertLog(MaintenanceLogsManager::MM25_ARCHIVE_MIGRATION, $log_string);
  912. PrintHelper::PrintToFile( $this->GetLogFolder(), $this->GetLogFile(), date('H:i:s') . " : " . $log_string . "\n", "ab+", 2 );
  913. }
  914. else
  915. {
  916. $res = $this->InsertCategoryBlockValue( $action_result['file_id'], 1001, $article->Article_IssueNb, "" );
  917.  
  918. $log_string = " create file : " . $article_id . ".npp" . " (success) (" . $article_count . " of " . $total_count . ")";
  919. }
  920.  
  921. echo "\n" . $log_string;
  922. }
  923. }
  924. }
  925.  
  926. function WriteToLog( $log_string )
  927. {
  928. $maintenancelogs_obj = new MaintenanceLogsManager();
  929. $maintenancelogs_obj->InsertLog( MaintenanceLogsManager::MM25_ARCHIVE_MIGRATION, $log_string );
  930. PrintHelper::PrintToFile( $this->GetLogFolder(), $this->GetLogFile(), date( 'H:i:s' ) . " : " . $log_string . "\n", "ab+", 2 );
  931. }
  932.  
  933.  
  934. function CreateFolderIfNotExist( $dir_path )
  935. {
  936. $file_manager_obj = new FileManager();
  937.  
  938. $org_dir_path = $dir_path;
  939.  
  940. $action_result['error'] = 0;
  941.  
  942. $dir_path = explode( "/" , $dir_path );
  943. $all_paths = array();
  944.  
  945. for( $i = 0 ; $i < count( $dir_path ) - 1 ; $i++ )
  946. {
  947. /** fill path of every folder */
  948. $all_paths[$i] = "./";
  949.  
  950. for( $k = 1 ; $k <= $i ; $k++ )
  951. {
  952. $all_paths[$i] .= $dir_path[ $k ] . "/";
  953. }
  954. }
  955.  
  956. for( $i = 0 ; $i < count( $all_paths ) ; $i++ )
  957. {
  958. $full_path = DirectoryHelper::ConvertSLPathFromRelativeToFull( $all_paths[$i], $this->sl_paths[ $this->GetSLID() ] );
  959.  
  960. $full_path = TextHelper::ConvertFromUTF8ToWIN1256( $full_path );
  961.  
  962. if( !is_dir( $full_path ) )
  963. {
  964. $dir_path = dirname( $all_paths[$i] ) . "/";
  965.  
  966. $dir_id = $file_manager_obj->RetrieveDirIdFromPath( $dir_path, $this->GetSLID() );
  967.  
  968. $folder_info = array();
  969. $folder_info['dir_path'] = $dir_path;
  970. $folder_info['dir_id'] = $dir_id;
  971. $folder_info['folder_name'] = basename( $all_paths[$i] );
  972. $folder_info['sf_indexing_flag'] = 0;
  973. $folder_info['coming_from'] = 18;
  974. $folder_info['sl_id'] = $this->GetSLID();
  975. $folder_info['storage_path'] = $this->sl_paths[ $this->GetSLID() ];
  976.  
  977. $result = $file_manager_obj->CreateFolder( $folder_info );
  978. //print_r($folder_info);
  979. //print_r($result);
  980. $action_result['directory_id'] = $result['sf_id'];
  981.  
  982. if( $result['error'] )
  983. {
  984. $action_result['error'] = 1;
  985. }
  986.  
  987. //DirectoryHelper::UpdateFolderCount( $dir_id );
  988. }
  989. else
  990. {
  991. $dir_id = $file_manager_obj->RetrieveDirIdFromPath( implode("/", $dir_path ), $this->GetSLID() );
  992.  
  993. $action_result['directory_id'] = $dir_id;
  994. }
  995. }
  996.  
  997. return $action_result;
  998. }
  999.  
  1000. function mb_pathinfo( $filepath )
  1001. {
  1002. $ret = array();
  1003. preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $filepath, $m );
  1004. if( $m[1] ) $ret['dirname'] = str_replace("\\", "/", $m[1] );
  1005. if( $m[2] ) $ret['basename'] = $m[2];
  1006. if( $m[5] ) $ret['extension'] = $m[5];
  1007. if( $m[3] ) $ret['filename'] = $m[3] . "." . $m[5];
  1008. return $ret;
  1009. }
  1010. }
  1011.  
  1012. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement