@@ -932,6 +932,53 @@ function getHistoryValue($varname, $time, $nerest = false)
932932 }
933933}
934934
935+
936+ function cleanUpValueHistory ($ value_id , $ max_age_days , $ data_type = 0 )
937+ {
938+ $ total_removed = 0 ;
939+
940+ if (defined ('SEPARATE_HISTORY_STORAGE ' ) && SEPARATE_HISTORY_STORAGE == 1 ) {
941+ $ table_name = 'phistory_value_ ' .$ value_id ;
942+ } else {
943+ $ table_name = 'phistory ' ;
944+ }
945+
946+ $ start_tm = date ('Y-m-d H:i:s ' , (time () - $ max_age_days * 24 * 60 * 60 ));
947+ $ qry = "VALUE_ID=' " . $ value_id . "' AND ADDED<(' " . $ start_tm . "') " ;
948+
949+ if ($ data_type == 5 ) {
950+ $ values = SQLSelect ("SELECT * FROM $ table_name WHERE $ qry " );
951+ $ totalv = count ($ values );
952+ for ($ iv = 0 ; $ iv < $ totalv ; $ iv ++) {
953+ $ file_path = ROOT . 'cms/images/ ' . $ values [$ iv ]['VALUE ' ];
954+ if ($ values [$ iv ]['VALUE ' ] != '' && file_exists ($ file_path )) {
955+ unlink ($ file_path );
956+ }
957+ }
958+ }
959+
960+ $ tmp = SQLSelectOne ("SELECT COUNT(*) as TOTAL FROM $ table_name WHERE $ qry " );
961+ if (isset ($ tmp ['TOTAL ' ]) && $ tmp ['TOTAL ' ]>0 ) {
962+ $ total_removed = (int )$ tmp ['TOTAL ' ];
963+ SQLExec ("DELETE FROM $ table_name WHERE $ qry " );
964+ }
965+ return $ total_removed ;
966+ }
967+
968+ function cleanUpPropertyHistory ($ property_id , $ max_age_days )
969+ {
970+ $ total_removed = 0 ;
971+ $ property = SQLSelectOne ("SELECT * FROM properties WHERE ID= " .(int )$ property_id );
972+ if (isset ($ property ['ID ' ])) {
973+ $ pvalues = SQLSelect ("SELECT * FROM pvalues WHERE PROPERTY_ID=' " . $ property_id . "' " );
974+ $ total = count ($ pvalues );
975+ for ($ i = 0 ; $ i < $ total ; $ i ++) {
976+ $ total_removed +=cleanUpValueHistory ($ pvalues [$ i ]['ID ' ], $ max_age_days , $ property ['DATA_TYPE ' ]);
977+ }
978+ }
979+ return $ total_removed ;
980+ }
981+
935982/**
936983 * Summary of setGlobal
937984 * @param mixed $varname Variable name
0 commit comments