Skip to content

Commit 44ce541

Browse files
committed
Merge branch 'develop' of github.com:OS2web/os2web_cp_service into develop
2 parents 117f6da + 945456a commit 44ce541

File tree

1 file changed

+40
-46
lines changed

1 file changed

+40
-46
lines changed

os2web_cp_service.module

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,27 +1078,27 @@ function _os2web_cp_service_document_download($file_id) {
10781078
* @param string $path_to_pdf
10791079
* path to the pdf version of the file
10801080
*/
1081-
function _os2web_cp_service_document_convert($file_id, $path_to_pdf) {
1082-
// If does not exist, send for redownloading.
1083-
if (!file_exists($path_to_pdf)) {
1084-
db_update('os2web_cp_service_documents_conversion')
1085-
->fields(array(
1086-
'filepath_pdf' => NULL,
1087-
'status' => NULL,
1088-
))
1081+
function _os2web_cp_service_document_convert($file_id, $path_to_pdf){
1082+
if (!file_exists($path_to_pdf)){//if does not exist, send for redownloading
1083+
db_update('os2web_cp_service_documents_conversion')
1084+
->fields(array(
1085+
'filepath_pdf' => null,
1086+
'status' => null,
1087+
))
10891088
->condition('file_id', $file_id)
10901089
->execute();
1091-
}
1092-
else {
1093-
shell_exec('pdf2htmlEX ' . $path_to_pdf . ' --dest-dir ' . file_directory_temp());
1094-
db_update('os2web_cp_service_documents_conversion')
1095-
->fields(array(
1096-
'filepath_html' => $path_to_pdf . '.html',
1097-
'status' => 'converted',
1098-
))
1099-
->condition('file_id', $file_id)
1100-
->execute();
1101-
}
1090+
} else {
1091+
$file_name = explode('/', $path_to_pdf);
1092+
1093+
shell_exec('pdf2htmlEX ' . $path_to_pdf . ' --single-html 0 --dest-dir ' . file_directory_temp() . '/' . $file_id);//saving in separate directory
1094+
db_update('os2web_cp_service_documents_conversion')
1095+
->fields(array(
1096+
'filepath_html' => file_directory_temp() . '/' . $file_id . '/' . end($file_name) . '.html',
1097+
'status' => 'converted',
1098+
))
1099+
->condition('file_id', $file_id)
1100+
->execute();
1101+
}
11021102
}
11031103

11041104
/**
@@ -1123,60 +1123,54 @@ function _os2web_cp_service_document_convert($file_id, $path_to_pdf) {
11231123
* Path to the html version of the file
11241124
*/
11251125
function _os2web_cp_service_update_case_metadata($file_id, $case_nid, $path_to_pdf, $path_to_html) {
1126-
// If does not exist, send for reconverting.
1127-
// PDF existence will be checked on that step as well.
1128-
if (!file_exists($path_to_html)) {
1129-
db_update('os2web_cp_service_documents_conversion')
1130-
->fields(array(
1131-
'filepath_html' => NULL,
1132-
'status' => 'downloaded',
1133-
))
1134-
->condition('file_id', $file_id)
1135-
->execute();
1136-
}
1137-
else {
1126+
if (!file_exists($path_to_html)){//if does not exist, send for reconverting. PDF existence will be checked on that step as well.
1127+
db_update('os2web_cp_service_documents_conversion')
1128+
->fields(array(
1129+
'filepath_html' => null,
1130+
'status' => 'downloaded',
1131+
))
1132+
->condition('file_id', $file_id)
1133+
->execute();
1134+
} else {
11381135
$case_node = node_load($case_nid);
1139-
if (!$case_node) {
1136+
if (!$case_node){
11401137
db_update('os2web_cp_service_documents_conversion')
11411138
->fields(array(
1142-
'status' => 'ERROR: node not found',
1139+
'status' => 'ERROR: node not found',
11431140
))
11441141
->condition('file_id', $file_id)
11451142
->execute();
1146-
}
1147-
else {
1143+
} else {
11481144
$text = file_get_contents($path_to_html);
11491145

11501146
// Html tags removing.
11511147
// Removing unneeded paragraphs.
11521148
$text = str_replace('<p>&nbsp;</p>', ' ', $text);
1153-
// Removing style tags.
1154-
$text = preg_replace('#<style(.*?)>(.*?)</style>#is', ' ', $text);
1155-
// Removing scripts tags.
1149+
// Removing script tags.
11561150
$text = preg_replace('#<script(.*?)>(.*?)</script>#is', ' ', $text);
11571151
$text = str_replace("\r\n", " ", strip_tags($text));
11581152
$text = str_replace("\n\r", " ", $text);
11591153
$text = str_replace("\n", " ", $text);
11601154
$text = str_replace("\r", " ", $text);
11611155
if (isset($case_node->field_os2web_cp_service_searchmt[LANGUAGE_NONE][0]['value'])) {
1162-
$search_metadata = $case_node->field_os2web_cp_service_searchmt[LANGUAGE_NONE][0]['value'] . $text;
1156+
$search_metadata = $case_node->field_os2web_cp_service_searchmt[LANGUAGE_NONE][0]['value'] . $text;
11631157
}
11641158
else {
1165-
$search_metadata = $text;
1159+
$search_metadata = $text;
11661160
}
11671161
$case_node->field_os2web_cp_service_searchmt[LANGUAGE_NONE][0]['value'] = $search_metadata;
11681162
node_save($case_node);
1169-
1163+
11701164
db_update('os2web_cp_service_documents_conversion')
11711165
->fields(array(
1172-
'status' => 'done',
1166+
'status' => 'done',
11731167
))
11741168
->condition('file_id', $file_id)
11751169
->execute();
1176-
1177-
// Tmp files cleanup.
1178-
unlink($path_to_html);
1170+
1171+
//tmp files cleanup
1172+
file_unmanaged_delete_recursive(file_directory_temp() . '/' . $file_id);
11791173
unlink($path_to_pdf);
11801174
}
1181-
}
1175+
}
11821176
}

0 commit comments

Comments
 (0)