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