PageRenderTime 226ms CodeModel.GetById 141ms app.highlight 18ms RepoModel.GetById 63ms app.codeStats 0ms

/package/app/app/alpha/apps/kaltura/modules/system/actions/statusAction.class.php

https://bitbucket.org/pandaos/kaltura
PHP | 369 lines | 279 code | 77 blank | 13 comment | 25 complexity | 2e708239cac564c5493703e8728184e7 MD5 | raw file
  1<?php
  2/**
  3 * @package    Core
  4 * @subpackage system
  5 * @deprecated
  6 */
  7require_once ( "kalturaSystemAction.class.php" );
  8
  9/**
 10 * @package    Core
 11 * @subpackage system
 12 * @deprecated
 13 */
 14class statusAction extends kalturaSystemAction
 15{
 16	private $connection;
 17	
 18	private function dumpOOConvertErrors($query)
 19	{
 20		$headerStyle = "bgcolor='lightgray'";
 21		$oddStyle = "bgcolor='cyan'";
 22		$evenStyle = "bgcolor='lightblue'";
 23		
 24		$statement = $this->connection->prepareStatement($query);
 25	    $resultset = $statement->executeQuery();
 26		
 27		$has_results = $resultset->getRecordCount() > 0;
 28		$title = "OOConversion Errors";
 29		
 30		echo "<H2>$title ".($has_results ? "" : "- NONE")."</H2>";
 31		echo $query;
 32		
 33		if ($has_results)
 34		{
 35			$lines = array();
 36			$lines[] = array();
 37			$lines[] = array();
 38    		
 39			while ($resultset->next())
 40			{
 41				$partner_id = $resultset->getInt("partner_id");
 42				$entry_id = $resultset->getString("entry_id");
 43				$date = $resultset->getDate("date", "%Y-%m-%d %H:%M:%S");
 44				$diff = $resultset->getString("diff");
 45				$source = "";
 46				
 47				$entry = entryPeer::retrieveByPK($entry_id);
 48				
 49				if ($entry)
 50				{
 51					$source = $entry->getSource();
 52					
 53					$batchjob_query = "SELECT description FROM batch_job WHERE job_type=".BatchJobType::IMPORT." and entry_id='$entry_id'";
 54					$batchjob_statement = $this->connection->prepareStatement($batchjob_query);
 55				    $batchjob_resultset = $batchjob_statement->executeQuery();
 56				    $batchjob_description = "NO BATCHJOB";
 57				    
 58					while ($batchjob_resultset->next())
 59					{
 60						$batchjob_description = $batchjob_resultset->get("description");
 61						break;
 62					}
 63					
 64					$data_path = myContentStorage::getFSContentRootPath() . $entry->getDataPath();
 65					$size = filesize($data_path);
 66					
 67					$list_type = $size > 0 ? 0 : 1;
 68					$cnt = count($lines[$list_type]) + 1;
 69					$lines[$list_type][] = "<TD>$cnt</TD><TD>$partner_id</TD><TD>$entry_id</TD><TD><A target='_blank' href='/index.php/system/investigate?entry_id=$entry_id'>$data_path</A></TD><TD>$size</TD><TD>$source</TD><TD>$date</TD><TD>$diff</TD><TD>$batchjob_description</TD>";
 70				}
 71			}
 72			
 73			for($j = 0; $j < 2; $j++)
 74			{
 75				if (!count($lines[$j]))
 76					continue;
 77					
 78				echo "<TABLE>\n";
 79				echo "<THEAD>\n";
 80				echo "<TR $headerStyle><TH>#</TH><TH>PARTNER_ID</TH><TH>ID</TH><TH>PATH</TH><TH>SIZE</TH><TH>SOURCE</TH><TH>LAST DATE</TH><TH>PASSED TIME</TH><TH>IMPORT ERROR</TH></TR>";
 81					
 82				echo "</THEAD>\n";
 83				echo "<TBODY>\n";
 84			
 85				$i = 0;
 86				foreach($lines[$j] as $line)
 87				{
 88					$style = ++$i % 2 ? $evenStyle : $oddStyle;
 89					echo "<TR $style>$line</TR>";
 90				}
 91				
 92				echo "</TBODY>\n";
 93				echo "</TABLE>\n";
 94				echo "<BR/>\n";
 95			}
 96		}
 97	}
 98
 99	private function dumpConvertErrors($query)
100	{
101		$headerStyle = "bgcolor='lightgray'";
102		$oddStyle = "bgcolor='cyan'";
103		$evenStyle = "bgcolor='lightblue'";
104		
105		$statement = $this->connection->prepareStatement($query);
106	    $resultset = $statement->executeQuery();
107		
108		$has_results = $resultset->getRecordCount() > 0;
109		$title = "Conversion Errors";
110		
111		echo "<H2>$title ".($has_results ? "" : "- NONE")."</H2>";
112		echo $query;
113		
114		if ($has_results)
115		{
116			$lines = array();
117			$lines[] = array();
118			$lines[] = array();
119    		
120			while ($resultset->next())
121			{
122				$partner_id = $resultset->getInt("partner_id");
123				$entry_id = $resultset->getString("id");
124				$source = $resultset->getInt("source");
125				$date = $resultset->getDate("date", "%Y-%m-%d %H:%M:%S");
126				$diff = $resultset->getString("diff");
127				
128				$entry = entryPeer::retrieveByPK($entry_id);
129				
130				if ($entry)
131				{
132					$batchjob_query = "SELECT description FROM batch_job WHERE job_type=".BatchJobType::IMPORT." and entry_id='$entry_id'";
133					$batchjob_statement = $this->connection->prepareStatement($batchjob_query);
134				    $batchjob_resultset = $batchjob_statement->executeQuery();
135				    $batchjob_description = "NO BATCHJOB";
136				    
137					while ($batchjob_resultset->next())
138					{
139						$batchjob_description = $batchjob_resultset->get("description");
140						break;
141					}
142					
143					$data_path = myContentStorage::getFSContentRootPath() . $entry->getDataPath();
144					$data_dir = pathinfo( $data_path, PATHINFO_DIRNAME );
145					$archive_file = $archive_path = str_replace( "content/entry" ,  "archive" , $data_dir );
146					$archive_files = glob ( $archive_path . "/{$entry_id}.*" );
147					$archive_file = "MISSING";
148					$size = "";
149					
150					if (count($archive_files))
151					{
152						$archive_file = pathinfo( $archive_files[0], PATHINFO_BASENAME );
153						$size = filesize($archive_files[0]);
154					}
155					
156					$list_type = $size > 100000 ? 0 : 1;
157					$cnt = count($lines[$list_type]) + 1;
158					$lines[$list_type][] = "<TD>$cnt</TD><TD>$partner_id</TD><TD>$entry_id</TD><TD><A target='_blank' href='/index.php/system/investigate?entry_id=$entry_id'>$data_path</A></TD><TD><A target='_blank' href='/index.php/system/investigate?entry_id=$entry_id'>$archive_file</A></TD><TD>$size</TD><TD>$source</TD><TD>$date</TD><TD>$diff</TD><TD>$batchjob_description</TD>";
159				}
160			}
161			
162			for($j = 0; $j < 2; $j++)
163			{
164				if (!count($lines[$j]))
165					continue;
166					
167				echo "<TABLE>\n";
168				echo "<THEAD>\n";
169				echo "<TR $headerStyle><TH>#</TH><TH>PARTNER_ID</TH><TH>ID</TH><TH>PATH</TH><TH>ARCHIVE</TH><TH>SIZE</TH><TH>SOURCE</TH><TH>LAST DATE</TH><TH>PASSED TIME</TH><TH>IMPORT ERROR</TH></TR>";
170					
171				echo "</THEAD>\n";
172				echo "<TBODY>\n";
173			
174				$i = 0;
175				foreach($lines[$j] as $line)
176				{
177					$style = ++$i % 2 ? $evenStyle : $oddStyle;
178					echo "<TR $style>$line</TR>";
179				}
180				
181				echo "</TBODY>\n";
182				echo "</TABLE>\n";
183				echo "<BR/>\n";
184			}
185		}
186	}
187	
188	private function dumpQuery($query, $title, $status_names = null)
189	{
190		if (!$status_names)
191			$status_names = array();
192		
193		$headerStyle = "bgcolor='lightgray'";
194		$oddStyle = "bgcolor='cyan'";
195		$evenStyle = "bgcolor='lightblue'";
196		
197		$statement = $this->connection->prepareStatement($query);
198	    $resultset = $statement->executeQuery();
199		
200		$has_results = $resultset->getRecordCount() > 0;
201		
202		echo "<H2>$title ".($has_results ? "" : "- NONE")."</H2>";
203		echo $query;
204		
205		if ($has_results)
206		{
207			echo "<TABLE>\n";
208			echo "<THEAD>\n";
209			echo "<TR $headerStyle><TH>STATUS</TH><TH>COUNT</TH><TH>LAST DATE</TH><TH>PASSED TIME</TH></TR>";
210			echo "</THEAD>\n";
211			echo "<TBODY>\n";
212			
213			$i = 0;
214			while ($resultset->next())
215			{
216				$style = ++$i % 2 ? $evenStyle : $oddStyle;
217    		
218				$status = $resultset->getInt("status");
219				$status = @$status_names[$status]. " ($status)";
220				$count = $resultset->getInt("count");
221				$date = $resultset->getDate("date", "%Y-%m-%d %H:%M:%S");
222				$diff = $resultset->getString("diff");
223				echo "<TR $style><TD>$status</TD><TD>$count</TD><TD>$date</TD><TD>$diff</TD></TR>";
224			}
225	    
226			echo "</TBODY>\n";
227			echo "</TABLE>\n";
228		}
229	}
230	
231	public function execute()
232	{
233		ini_set("memory_limit","128M");
234		$this->forceSystemAuthentication();
235		
236		$amount = $this->getP ( "amount" );
237		if (!$amount)
238			$amount = 1;
239			
240		$interval = $this->getP ( "interval" );
241		if (!$interval)
242			$interval = "day";
243		
244		$partner_id = $this->getP ( "partner_id" );
245		if (strlen($partner_id) == 0)
246			$partner_id = "ALL";
247		
248			while(FALSE !== ob_get_clean());
249		
250		echo "<HTML><BODY>\n";
251		echo "<form>\n";
252		echo "Last ";
253		echo "<input name='amount' type='text' value='$amount'>&nbsp;";
254		echo "<input name='interval' type='radio' value='day' ".($interval == "day" ? "checked" : "").">days&nbsp;";
255		echo "<input name='interval' type='radio' value='hour' ".($interval == "hour" ? "checked" : "").">hours&nbsp;";
256		echo " Filter by partner ";
257		echo "<input name='partner_id' type='text' value='$partner_id'>&nbsp;";
258		echo "<input type='submit' style='color:black' name='go' value='Go'>\n";
259		echo "</form>\n";
260		
261		$partner_where = ($partner_id == "ALL") ? "" : " AND partner_id='$partner_id' ";
262
263		// use the slave rather than master !
264	    $this->connection = Propel::getConnection("propel2");
265		
266		$date_filter = " ADDDATE(NOW(), INTERVAL -$amount $interval) ";
267
268	    $entry_statuses = array(
269			entryStatus::ERROR_CONVERTING => "ERROR",
270			entryStatus::IMPORT => "IMPORT",
271			entryStatus::PRECONVERT => "PRECONVERT",
272			entryStatus::READY => "READY",
273			entryStatus::DELETED => "DELETED",
274			entryStatus::PENDING => "PENDING",
275			entryStatus::MODERATE => "MODERATE",
276			entryStatus::BLOCKED => "BLOCKED"
277		);
278		
279		$query = "select status,count(1) as count,max(created_at) as date,timediff(now(),max(created_at)) as diff from entry where type=1 and created_at>$date_filter $partner_where group by status order by status";
280	    
281	    $this->dumpQuery($query, "Entries", $entry_statuses);
282
283	    $query = "select status,count(1) as count,max(created_at) as date,timediff(now(),max(created_at)) as diff from entry where type=1 and media_type=1 and created_at>$date_filter $partner_where group by status order by status";
284	    
285	    $this->dumpQuery($query, "Video Entries", $entry_statuses);
286	    
287	    $entry_media_types = array(
288			entry::ENTRY_MEDIA_TYPE_AUTOMATIC => "Automatic",
289			entry::ENTRY_MEDIA_TYPE_ANY => "Any",
290			entry::ENTRY_MEDIA_TYPE_VIDEO => "Video",
291			entry::ENTRY_MEDIA_TYPE_IMAGE => "Image",
292			entry::ENTRY_MEDIA_TYPE_TEXT => "Text",
293			entry::ENTRY_MEDIA_TYPE_HTML => "HTML",
294			entry::ENTRY_MEDIA_TYPE_AUDIO => "Audio",
295			entry::ENTRY_MEDIA_TYPE_SHOW => "Roughcut",
296			entry::ENTRY_MEDIA_TYPE_SHOW_XML => "RoughcutXML",
297			entry::ENTRY_MEDIA_TYPE_BUBBLES => "Bubbles",
298			entry::ENTRY_MEDIA_TYPE_XML => "XML",
299			entry::ENTRY_MEDIA_TYPE_DOCUMENT => "Document",
300			entry::ENTRY_MEDIA_TYPE_SWF => "SWF"
301		);
302	    
303	    $query = "select media_type as status,count(1) as count,max(created_at) as date,timediff(now(),max(created_at)) as diff from entry where created_at>$date_filter $partner_where group by media_type order by media_type";
304	    
305	    $this->dumpQuery($query, "Entries by media type", $entry_media_types);
306
307	    $query = "select partner_id,id,source,created_at as date,timediff(now(),created_at) as diff from entry where type=1 and media_type=1 and status=-1 and created_at>$date_filter $partner_where order by int_id desc limit 100";
308	    
309	    $this->dumpConvertErrors($query);
310
311	    $job_statuses = array(
312			BatchJob::BATCHJOB_STATUS_PENDING => "PENDING",
313			BatchJob::BATCHJOB_STATUS_QUEUED => "QUEUED", 
314			BatchJob::BATCHJOB_STATUS_PROCESSING => "PROCESSING",
315			BatchJob::BATCHJOB_STATUS_PROCESSED => "PROCESSED",
316			BatchJob::BATCHJOB_STATUS_MOVEFILE => "MOVEFILE",
317			BatchJob::BATCHJOB_STATUS_FINISHED => "FINISHED",
318			BatchJob::BATCHJOB_STATUS_FAILED => "FAILED",
319			BatchJob::BATCHJOB_STATUS_ABORTED => "ABORTED",
320		);
321		
322	    $jobs = array(
323	   		BatchJobType::IMPORT => "Import",
324	   		BatchJobType::DELETE => "Delete",
325	   		BatchJobType::FLATTEN => "Flatten",
326	   		BatchJobType::BULKUPLOAD => "Bulk Upload",
327	   		BatchJobType::OOCONVERT => "OOConvert"
328	   		);
329	   		
330	   	foreach($jobs as $job_type => $job_name)
331	   	{
332		    $query = "select status,count(1) as count,max(created_at) as date, timediff(now(),max(created_at)) as diff from batch_job where job_type=$job_type and created_at>$date_filter $partner_where group by status order by status";
333		    
334		    $this->dumpQuery($query, $job_name, $job_statuses);
335		    
336			if ($job_type == BatchJobType::OOCONVERT)
337			    $this->dumpOOConvertErrors("select partner_id,id,entry_id,created_at as date,timediff(now(),created_at) as diff from batch_job where job_type=$job_type and created_at>$date_filter $partner_where AND status=".BatchJob::BATCHJOB_STATUS_FAILED);
338	   	}
339	    
340	    $notification_statuses = array(
341			BatchJob::BATCHJOB_STATUS_PENDING => "PENDING",
342			BatchJob::BATCHJOB_STATUS_FINISHED => "SENT",
343			BatchJob::BATCHJOB_STATUS_FAILED => "ERROR",
344			BatchJob::BATCHJOB_STATUS_RETRY => "SHOULD_RESEND",
345//			BatchJob::BATCHJOB_STATUS_FAILED => "ERROR_RESENDING",
346//			BatchJob::BATCHJOB_STATUS_FINISHED => "SENT_SYNCH",
347		);
348		
349	   	$query = "select status,count(1) as count,max(created_at) as date, timediff(now(),max(created_at)) as diff from notification where created_at>$date_filter $partner_where group by status order by status";
350	    
351	    $this->dumpQuery($query, "Notifications", $notification_statuses);
352		
353	    $mail_statuses = array(
354			kMailJobData::MAIL_STATUS_PENDING => "PENDING",
355			kMailJobData::MAIL_STATUS_SENT => "SENT",
356			kMailJobData::MAIL_STATUS_ERROR => "ERROR"
357		);
358		
359	   	$query = "select status,count(1) as count,max(created_at) as date, timediff(now(),max(created_at)) as diff from mail_job where created_at>$date_filter group by status order by status";
360	    
361	    $this->dumpQuery($query, "Mail Job", $mail_statuses);
362		
363	    echo "</BODY></HTML>\n";
364		
365	    die;
366	}
367}
368
369?>