Skip to content

Commit a4c0ece

Browse files
author
Stanislav
committed
reverting to last version
1 parent dfcbd18 commit a4c0ece

10 files changed

+5
-250
lines changed

css/os2web_cp_service.css

100755100644
File mode changed.

images/cal.png

100755100644
File mode changed.

js/jquery.qtip-1.0.0-rc3.min.js

100755100644
File mode changed.

js/os2web_cp_service.js

100755100644
File mode changed.

os2web_cp_service.info

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies[] = menu
1717
dependencies[] = node
1818
dependencies[] = number
1919
dependencies[] = options
20-
;dependencies[] = os2web_acadre_esdh
20+
dependencies[] = os2web_acadre_esdh
2121
dependencies[] = page_manager
2222
dependencies[] = panels
2323
dependencies[] = pathauto

os2web_cp_service.install

100755100644
Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,3 @@ function os2web_cp_service_install() {
1919
// taxonomy_term_save($term);
2020
// }
2121
}
22-
23-
function os2web_cp_service_schema() {
24-
$schema['os2web_cp_service_documents_conversion'] = array(
25-
'description' => 'This table is used as schedule for PDF -> HTML convertion of CP Documents',
26-
'fields' => array(
27-
'file_id' => array(
28-
'description' => 'The ID of the document file located remotely',
29-
'type' => 'varchar',
30-
'length' => 1024,
31-
'serialize' => TRUE,
32-
),
33-
'case_nid' => array(
34-
'description' => 'The nid of the CP Case, which metadata field should be updated with file content',
35-
'type' => 'int',
36-
'unsigned' => TRUE,
37-
),
38-
'filepath_pdf' => array(
39-
'description' => 'The path of the downloaded PDF',
40-
'type' => 'varchar',
41-
'length' => 1024,
42-
'serialize' => TRUE,
43-
),
44-
'filepath_html' => array(
45-
'description' => 'The path of the created HTML output',
46-
'type' => 'varchar',
47-
'length' => 1024,
48-
'serialize' => TRUE,
49-
),
50-
'status' => array(
51-
'description' => 'The information about the job',
52-
'type' => 'varchar',
53-
'length' => 1024,
54-
'serialize' => TRUE,
55-
),
56-
),
57-
'primary key' => array('case_nid'),
58-
);
59-
return $schema;
60-
}

os2web_cp_service.make

100755100644
File mode changed.

os2web_cp_service.module

100755100644
Lines changed: 3 additions & 209 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
include_once 'os2web_cp_service.features.inc';
9-
define('DEFAULT_CASE_FILE_LIMIT', 50);//number of files to handle at once
109

1110
/**
1211
* Implements hook_init().
@@ -66,7 +65,9 @@ function os2web_cp_service_handler() {
6665
* Callback for the file provider service.
6766
*/
6867
function os2web_gf_service_handler($file_id) {
68+
6969
if ($url = variable_get('os2web_cp_service_cp_document_fileurl')) {
70+
7071
$username = variable_get('os2web_cp_service_endpoint_user');
7172
$password = variable_get('os2web_cp_service_endpoint_password');
7273
if (!empty($username) && !empty($password)) {
@@ -105,6 +106,7 @@ function os2web_gf_service_handler($file_id) {
105106
$nids = (isset($result['node']))?array_keys($result['node']) : NULL;
106107

107108
$node = node_load(array_pop($nids));
109+
108110
if ($node) {
109111
$filename = str_replace('/', '_', $node->field_os2web_cp_service_doc_id[LANGUAGE_NONE][0]['value'] . '.' . os2web_cp_service_get_extension_from_mime($header['content_type']));
110112
drupal_add_http_header('Content-Disposition', 'attachment; filename=' . $filename);
@@ -518,8 +520,6 @@ function os2web_cp_service_create_document(array $data) {
518520
}
519521
if ($is_missing) {
520522
$cnode->field_os2web_cp_service_doc_ref[LANGUAGE_NONE][]['target_id'] = $node->nid;
521-
//adding for pdf 2 html conversion, [email protected]
522-
os2web_cp_service_schedule_document_pdf2html_conversion($data['fields']['FilID'], $cnode->nid);
523523
node_save($cnode);
524524
}
525525
}
@@ -881,209 +881,3 @@ function os2web_cp_service_get_extension_from_mime($mime) {
881881
$pieces = explode('/', $mime);
882882
return array_pop($pieces);
883883
}
884-
885-
/**
886-
* Schedules a document for pdf to html conversion by adding the document's to database table.
887-
*
888-
* @param string $file_id id of the file on remove server
889-
* @param int $case_nid nid of the destination case, which metadata field should be updated
890-
*
891-
* @return none
892-
*/
893-
function os2web_cp_service_schedule_document_pdf2html_conversion($file_id, $case_nid){
894-
db_insert('os2web_cp_service_documents_conversion')
895-
->fields(array(
896-
'file_id' => $file_id,
897-
'case_nid' => $case_nid,
898-
'filepath_pdf' => NULL,
899-
'filepath_html' => NULL,
900-
'status' => NULL,
901-
))
902-
->execute();
903-
}
904-
905-
/**
906-
* Cron implementation.
907-
* Goes through the enrties in database table,
908-
* downloads the documents as pdf,
909-
* and converts the documents from pdf to html and updates the case metadata field with the document contents.
910-
*
911-
* @return none
912-
*/
913-
function os2web_cp_service_cron(){
914-
//download
915-
$query = db_select('os2web_cp_service_documents_conversion', 'dc');
916-
$query->fields('dc',array('file_id'))
917-
->isNull('dc.status')
918-
->range(0,DEFAULT_CASE_FILE_LIMIT);
919-
$result = $query->execute();
920-
while($record = $result->fetchAssoc()) {
921-
_os2web_cp_service_document_download($record['file_id']);
922-
}
923-
924-
//convert
925-
$query = db_select('os2web_cp_service_documents_conversion', 'dc');
926-
$query->fields('dc',array('file_id', 'filepath_pdf'))
927-
->condition('dc.status', 'downloaded')
928-
->range(0,DEFAULT_CASE_FILE_LIMIT);
929-
$result = $query->execute();
930-
while($record = $result->fetchAssoc()) {
931-
_os2web_cp_service_document_convert($record['file_id'], $record['filepath_pdf']);
932-
}
933-
934-
//field updating
935-
$query = db_select('os2web_cp_service_documents_conversion', 'dc');
936-
$query->fields('dc',array('file_id', 'case_nid', 'filepath_pdf', 'filepath_html'))
937-
->condition('dc.status', 'converted')
938-
->range(0,DEFAULT_CASE_FILE_LIMIT);
939-
$result = $query->execute();
940-
while($record = $result->fetchAssoc()) {
941-
_os2web_cp_service_update_case_metadata($record['file_id'], $record['case_nid'], $record['filepath_pdf'], $record['filepath_html']);
942-
}
943-
}
944-
945-
/**
946-
* Download the document file and places it into the temporary location
947-
* also updates the database entry with the created filepath
948-
*
949-
* If file is not found on the remote server, the status is changed to "ERROR: 404 not found"
950-
* If ULR returns anything else than 200 http code, the status is chaned to "ERROR: {httpCode}"
951-
*
952-
* @param $file_id string id of the document file
953-
*
954-
* @return none
955-
*/
956-
function _os2web_cp_service_document_download($file_id){
957-
$url = $GLOBALS['base_url'] . '/?q=os2web/service/gf/v1/' . $file_id;//address of remote file
958-
$tmpfname = tempnam(file_directory_temp(), "os2web_cp_document_");//path to where the file will be downloaded
959-
960-
$fp = fopen($tmpfname, 'w');
961-
962-
$ch = curl_init($url);
963-
curl_setopt($ch, CURLOPT_FILE, $fp);
964-
$data= curl_exec($ch);
965-
966-
//Check for 404 (file not found)
967-
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
968-
curl_close($ch);
969-
fclose($fp);
970-
971-
if ($httpCode == 404) {
972-
print_r('404');
973-
db_update('os2web_cp_service_documents_conversion')
974-
->fields(array(
975-
'status' => 'ERROR: 404 not found',
976-
))
977-
->condition('file_id', $file_id)
978-
->execute();
979-
} else if ($httpCode == 200) {
980-
db_update('os2web_cp_service_documents_conversion')
981-
->fields(array(
982-
'filepath_pdf' => $tmpfname,
983-
'status' => 'downloaded',
984-
))
985-
->condition('file_id', $file_id)
986-
->execute();
987-
} else {//unknown error
988-
db_update('os2web_cp_service_documents_conversion')
989-
->fields(array(
990-
'status' => 'ERROR: ' . $httpCode,
991-
))
992-
->condition('file_id', $file_id)
993-
->execute();
994-
}
995-
}
996-
997-
/**
998-
* Converts the downloaded pdf into HTML
999-
* also updates the database entry with the created filepath
1000-
*
1001-
* If PDF file is not found, the status is changes to NULL, so that the next cron job will download the file again.
1002-
*
1003-
* @param $file_id string id of the document file
1004-
* @param $path_to_pdf string path to the pdf version of the file
1005-
*
1006-
* @return none
1007-
*/
1008-
function _os2web_cp_service_document_convert($file_id, $path_to_pdf){
1009-
if (!file_exists($path_to_pdf)){//if does not exist, send for redownloading
1010-
db_update('os2web_cp_service_documents_conversion')
1011-
->fields(array(
1012-
'filepath_pdf' => null,
1013-
'status' => null,
1014-
))
1015-
->condition('file_id', $file_id)
1016-
->execute();
1017-
} else {
1018-
shell_exec('pdf2htmlEX ' . $path_to_pdf . ' --dest-dir ' . file_directory_temp());
1019-
db_update('os2web_cp_service_documents_conversion')
1020-
->fields(array(
1021-
'filepath_html' => $path_to_pdf . '.html',
1022-
'status' => 'converted',
1023-
))
1024-
->condition('file_id', $file_id)
1025-
->execute();
1026-
}
1027-
}
1028-
1029-
/**
1030-
* Takes the convent of the html, removed everything except the pure text and then appends this text to case node search metadata field.
1031-
* In the end the temp files (pdf and html) are deleted.
1032-
*
1033-
* If HTML file is not found, the status will be changed to "downloaded" so that the text cron job will convert the file again.
1034-
* If case node is not found, the status will be chaned to "ERROR: node not found".
1035-
*
1036-
* @param $file_id string id of the document file
1037-
* @param $case_nid the node id the case node, which metadata should be updated
1038-
* @param $path_to_pdf string path to the pdf version of the file
1039-
* @param $path_to_html string path to the html version of the file
1040-
*
1041-
* @return none
1042-
*/
1043-
function _os2web_cp_service_update_case_metadata($file_id, $case_nid, $path_to_pdf, $path_to_html){
1044-
if (!file_exists($path_to_html)){//if does not exist, send for reconverting. PDF existence will be checked on that step as well.
1045-
db_update('os2web_cp_service_documents_conversion')
1046-
->fields(array(
1047-
'filepath_html' => null,
1048-
'status' => 'downloaded',
1049-
))
1050-
->condition('file_id', $file_id)
1051-
->execute();
1052-
} else {
1053-
$case_node = node_load($case_nid);
1054-
if (!$case_node){
1055-
db_update('os2web_cp_service_documents_conversion')
1056-
->fields(array(
1057-
'status' => 'ERROR: node not found',
1058-
))
1059-
->condition('file_id', $file_id)
1060-
->execute();
1061-
} else {
1062-
$text = file_get_contents($path_to_html);
1063-
1064-
//html tags removing
1065-
$text = str_replace('<p>&nbsp;</p>', ' ', $text); //removing unneeded paragraphs
1066-
$text = preg_replace('#<style(.*?)>(.*?)</style>#is', ' ', $text);//removing style tags
1067-
$text = preg_replace('#<script(.*?)>(.*?)</script>#is', ' ', $text);//removing scripts tags
1068-
$text = str_replace("\r\n", " ", strip_tags($text));
1069-
$text = str_replace("\n\r", " ", $text);
1070-
$text = str_replace("\n", " ", $text);
1071-
$text = str_replace("\r", " ", $text);
1072-
1073-
$search_metadata = $case_node->field_os2web_cp_service_searchmt['und'][0]['value'] . $text;
1074-
$case_node->field_os2web_cp_service_searchmt['und'][0]['value'] = $search_metadata;
1075-
node_save($case_node);
1076-
1077-
db_update('os2web_cp_service_documents_conversion')
1078-
->fields(array(
1079-
'status' => 'done',
1080-
))
1081-
->condition('file_id', $file_id)
1082-
->execute();
1083-
1084-
//tmp files cleanup
1085-
unlink($path_to_html);
1086-
unlink($path_to_pdf);
1087-
}
1088-
}
1089-
}

os2web_cp_service.strongarm.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function os2web_cp_service_strongarm() {
8787
$strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */
8888
$strongarm->api_version = 1;
8989
$strongarm->name = 'pathauto_punctuation_slash';
90-
$strongarm->value = '0';
90+
$strongarm->value = '2';
9191
$export['pathauto_punctuation_slash'] = $strongarm;
9292

9393
return $export;

theme/views-exposed-form--os2web-cp-service-cp-case-search.tpl.php

100755100644
File mode changed.

0 commit comments

Comments
 (0)