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

Language PHP Lines 369
MD5 Hash 2e708239cac564c5493703e8728184e7 Estimated Cost $7,019 (why?)
Repository https://bitbucket.org/pandaos/kaltura.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?php
/**
 * @package    Core
 * @subpackage system
 * @deprecated
 */
require_once ( "kalturaSystemAction.class.php" );

/**
 * @package    Core
 * @subpackage system
 * @deprecated
 */
class statusAction extends kalturaSystemAction
{
	private $connection;
	
	private function dumpOOConvertErrors($query)
	{
		$headerStyle = "bgcolor='lightgray'";
		$oddStyle = "bgcolor='cyan'";
		$evenStyle = "bgcolor='lightblue'";
		
		$statement = $this->connection->prepareStatement($query);
	    $resultset = $statement->executeQuery();
		
		$has_results = $resultset->getRecordCount() > 0;
		$title = "OOConversion Errors";
		
		echo "<H2>$title ".($has_results ? "" : "- NONE")."</H2>";
		echo $query;
		
		if ($has_results)
		{
			$lines = array();
			$lines[] = array();
			$lines[] = array();
    		
			while ($resultset->next())
			{
				$partner_id = $resultset->getInt("partner_id");
				$entry_id = $resultset->getString("entry_id");
				$date = $resultset->getDate("date", "%Y-%m-%d %H:%M:%S");
				$diff = $resultset->getString("diff");
				$source = "";
				
				$entry = entryPeer::retrieveByPK($entry_id);
				
				if ($entry)
				{
					$source = $entry->getSource();
					
					$batchjob_query = "SELECT description FROM batch_job WHERE job_type=".BatchJobType::IMPORT." and entry_id='$entry_id'";
					$batchjob_statement = $this->connection->prepareStatement($batchjob_query);
				    $batchjob_resultset = $batchjob_statement->executeQuery();
				    $batchjob_description = "NO BATCHJOB";
				    
					while ($batchjob_resultset->next())
					{
						$batchjob_description = $batchjob_resultset->get("description");
						break;
					}
					
					$data_path = myContentStorage::getFSContentRootPath() . $entry->getDataPath();
					$size = filesize($data_path);
					
					$list_type = $size > 0 ? 0 : 1;
					$cnt = count($lines[$list_type]) + 1;
					$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>";
				}
			}
			
			for($j = 0; $j < 2; $j++)
			{
				if (!count($lines[$j]))
					continue;
					
				echo "<TABLE>\n";
				echo "<THEAD>\n";
				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>";
					
				echo "</THEAD>\n";
				echo "<TBODY>\n";
			
				$i = 0;
				foreach($lines[$j] as $line)
				{
					$style = ++$i % 2 ? $evenStyle : $oddStyle;
					echo "<TR $style>$line</TR>";
				}
				
				echo "</TBODY>\n";
				echo "</TABLE>\n";
				echo "<BR/>\n";
			}
		}
	}

	private function dumpConvertErrors($query)
	{
		$headerStyle = "bgcolor='lightgray'";
		$oddStyle = "bgcolor='cyan'";
		$evenStyle = "bgcolor='lightblue'";
		
		$statement = $this->connection->prepareStatement($query);
	    $resultset = $statement->executeQuery();
		
		$has_results = $resultset->getRecordCount() > 0;
		$title = "Conversion Errors";
		
		echo "<H2>$title ".($has_results ? "" : "- NONE")."</H2>";
		echo $query;
		
		if ($has_results)
		{
			$lines = array();
			$lines[] = array();
			$lines[] = array();
    		
			while ($resultset->next())
			{
				$partner_id = $resultset->getInt("partner_id");
				$entry_id = $resultset->getString("id");
				$source = $resultset->getInt("source");
				$date = $resultset->getDate("date", "%Y-%m-%d %H:%M:%S");
				$diff = $resultset->getString("diff");
				
				$entry = entryPeer::retrieveByPK($entry_id);
				
				if ($entry)
				{
					$batchjob_query = "SELECT description FROM batch_job WHERE job_type=".BatchJobType::IMPORT." and entry_id='$entry_id'";
					$batchjob_statement = $this->connection->prepareStatement($batchjob_query);
				    $batchjob_resultset = $batchjob_statement->executeQuery();
				    $batchjob_description = "NO BATCHJOB";
				    
					while ($batchjob_resultset->next())
					{
						$batchjob_description = $batchjob_resultset->get("description");
						break;
					}
					
					$data_path = myContentStorage::getFSContentRootPath() . $entry->getDataPath();
					$data_dir = pathinfo( $data_path, PATHINFO_DIRNAME );
					$archive_file = $archive_path = str_replace( "content/entry" ,  "archive" , $data_dir );
					$archive_files = glob ( $archive_path . "/{$entry_id}.*" );
					$archive_file = "MISSING";
					$size = "";
					
					if (count($archive_files))
					{
						$archive_file = pathinfo( $archive_files[0], PATHINFO_BASENAME );
						$size = filesize($archive_files[0]);
					}
					
					$list_type = $size > 100000 ? 0 : 1;
					$cnt = count($lines[$list_type]) + 1;
					$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>";
				}
			}
			
			for($j = 0; $j < 2; $j++)
			{
				if (!count($lines[$j]))
					continue;
					
				echo "<TABLE>\n";
				echo "<THEAD>\n";
				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>";
					
				echo "</THEAD>\n";
				echo "<TBODY>\n";
			
				$i = 0;
				foreach($lines[$j] as $line)
				{
					$style = ++$i % 2 ? $evenStyle : $oddStyle;
					echo "<TR $style>$line</TR>";
				}
				
				echo "</TBODY>\n";
				echo "</TABLE>\n";
				echo "<BR/>\n";
			}
		}
	}
	
	private function dumpQuery($query, $title, $status_names = null)
	{
		if (!$status_names)
			$status_names = array();
		
		$headerStyle = "bgcolor='lightgray'";
		$oddStyle = "bgcolor='cyan'";
		$evenStyle = "bgcolor='lightblue'";
		
		$statement = $this->connection->prepareStatement($query);
	    $resultset = $statement->executeQuery();
		
		$has_results = $resultset->getRecordCount() > 0;
		
		echo "<H2>$title ".($has_results ? "" : "- NONE")."</H2>";
		echo $query;
		
		if ($has_results)
		{
			echo "<TABLE>\n";
			echo "<THEAD>\n";
			echo "<TR $headerStyle><TH>STATUS</TH><TH>COUNT</TH><TH>LAST DATE</TH><TH>PASSED TIME</TH></TR>";
			echo "</THEAD>\n";
			echo "<TBODY>\n";
			
			$i = 0;
			while ($resultset->next())
			{
				$style = ++$i % 2 ? $evenStyle : $oddStyle;
    		
				$status = $resultset->getInt("status");
				$status = @$status_names[$status]. " ($status)";
				$count = $resultset->getInt("count");
				$date = $resultset->getDate("date", "%Y-%m-%d %H:%M:%S");
				$diff = $resultset->getString("diff");
				echo "<TR $style><TD>$status</TD><TD>$count</TD><TD>$date</TD><TD>$diff</TD></TR>";
			}
	    
			echo "</TBODY>\n";
			echo "</TABLE>\n";
		}
	}
	
	public function execute()
	{
		ini_set("memory_limit","128M");
		$this->forceSystemAuthentication();
		
		$amount = $this->getP ( "amount" );
		if (!$amount)
			$amount = 1;
			
		$interval = $this->getP ( "interval" );
		if (!$interval)
			$interval = "day";
		
		$partner_id = $this->getP ( "partner_id" );
		if (strlen($partner_id) == 0)
			$partner_id = "ALL";
		
			while(FALSE !== ob_get_clean());
		
		echo "<HTML><BODY>\n";
		echo "<form>\n";
		echo "Last ";
		echo "<input name='amount' type='text' value='$amount'>&nbsp;";
		echo "<input name='interval' type='radio' value='day' ".($interval == "day" ? "checked" : "").">days&nbsp;";
		echo "<input name='interval' type='radio' value='hour' ".($interval == "hour" ? "checked" : "").">hours&nbsp;";
		echo " Filter by partner ";
		echo "<input name='partner_id' type='text' value='$partner_id'>&nbsp;";
		echo "<input type='submit' style='color:black' name='go' value='Go'>\n";
		echo "</form>\n";
		
		$partner_where = ($partner_id == "ALL") ? "" : " AND partner_id='$partner_id' ";

		// use the slave rather than master !
	    $this->connection = Propel::getConnection("propel2");
		
		$date_filter = " ADDDATE(NOW(), INTERVAL -$amount $interval) ";

	    $entry_statuses = array(
			entryStatus::ERROR_CONVERTING => "ERROR",
			entryStatus::IMPORT => "IMPORT",
			entryStatus::PRECONVERT => "PRECONVERT",
			entryStatus::READY => "READY",
			entryStatus::DELETED => "DELETED",
			entryStatus::PENDING => "PENDING",
			entryStatus::MODERATE => "MODERATE",
			entryStatus::BLOCKED => "BLOCKED"
		);
		
		$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";
	    
	    $this->dumpQuery($query, "Entries", $entry_statuses);

	    $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";
	    
	    $this->dumpQuery($query, "Video Entries", $entry_statuses);
	    
	    $entry_media_types = array(
			entry::ENTRY_MEDIA_TYPE_AUTOMATIC => "Automatic",
			entry::ENTRY_MEDIA_TYPE_ANY => "Any",
			entry::ENTRY_MEDIA_TYPE_VIDEO => "Video",
			entry::ENTRY_MEDIA_TYPE_IMAGE => "Image",
			entry::ENTRY_MEDIA_TYPE_TEXT => "Text",
			entry::ENTRY_MEDIA_TYPE_HTML => "HTML",
			entry::ENTRY_MEDIA_TYPE_AUDIO => "Audio",
			entry::ENTRY_MEDIA_TYPE_SHOW => "Roughcut",
			entry::ENTRY_MEDIA_TYPE_SHOW_XML => "RoughcutXML",
			entry::ENTRY_MEDIA_TYPE_BUBBLES => "Bubbles",
			entry::ENTRY_MEDIA_TYPE_XML => "XML",
			entry::ENTRY_MEDIA_TYPE_DOCUMENT => "Document",
			entry::ENTRY_MEDIA_TYPE_SWF => "SWF"
		);
	    
	    $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";
	    
	    $this->dumpQuery($query, "Entries by media type", $entry_media_types);

	    $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";
	    
	    $this->dumpConvertErrors($query);

	    $job_statuses = array(
			BatchJob::BATCHJOB_STATUS_PENDING => "PENDING",
			BatchJob::BATCHJOB_STATUS_QUEUED => "QUEUED", 
			BatchJob::BATCHJOB_STATUS_PROCESSING => "PROCESSING",
			BatchJob::BATCHJOB_STATUS_PROCESSED => "PROCESSED",
			BatchJob::BATCHJOB_STATUS_MOVEFILE => "MOVEFILE",
			BatchJob::BATCHJOB_STATUS_FINISHED => "FINISHED",
			BatchJob::BATCHJOB_STATUS_FAILED => "FAILED",
			BatchJob::BATCHJOB_STATUS_ABORTED => "ABORTED",
		);
		
	    $jobs = array(
	   		BatchJobType::IMPORT => "Import",
	   		BatchJobType::DELETE => "Delete",
	   		BatchJobType::FLATTEN => "Flatten",
	   		BatchJobType::BULKUPLOAD => "Bulk Upload",
	   		BatchJobType::OOCONVERT => "OOConvert"
	   		);
	   		
	   	foreach($jobs as $job_type => $job_name)
	   	{
		    $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";
		    
		    $this->dumpQuery($query, $job_name, $job_statuses);
		    
			if ($job_type == BatchJobType::OOCONVERT)
			    $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);
	   	}
	    
	    $notification_statuses = array(
			BatchJob::BATCHJOB_STATUS_PENDING => "PENDING",
			BatchJob::BATCHJOB_STATUS_FINISHED => "SENT",
			BatchJob::BATCHJOB_STATUS_FAILED => "ERROR",
			BatchJob::BATCHJOB_STATUS_RETRY => "SHOULD_RESEND",
//			BatchJob::BATCHJOB_STATUS_FAILED => "ERROR_RESENDING",
//			BatchJob::BATCHJOB_STATUS_FINISHED => "SENT_SYNCH",
		);
		
	   	$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";
	    
	    $this->dumpQuery($query, "Notifications", $notification_statuses);
		
	    $mail_statuses = array(
			kMailJobData::MAIL_STATUS_PENDING => "PENDING",
			kMailJobData::MAIL_STATUS_SENT => "SENT",
			kMailJobData::MAIL_STATUS_ERROR => "ERROR"
		);
		
	   	$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";
	    
	    $this->dumpQuery($query, "Mail Job", $mail_statuses);
		
	    echo "</BODY></HTML>\n";
		
	    die;
	}
}

?>
Back to Top