Skip to content

Commit d583fa7

Browse files
committed
Moved update hook to .install file.
1 parent 3c387f4 commit d583fa7

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

os2web_cp_service.install

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,11 @@ function os2web_cp_service_schema() {
5757
'primary key' => array('case_nid'),
5858
);
5959
return $schema;
60-
}
60+
}
61+
62+
/**
63+
* Update method installing the module's database without a need to uninstall/install it.
64+
*/
65+
function os2web_cp_service_update_7100(){
66+
drupal_install_schema('os2web_cp_service');
67+
}

os2web_cp_service.module

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function os2web_cp_service_handler() {
7474
function os2web_gf_service_handler($file_id) {
7575
if ($url = variable_get('os2web_cp_service_cp_document_fileurl')) {
7676
variable_set('os2web_cp_service_cp_document_fileurl', 'http://10.1.1.118/Traen%20Publishing%20File%20Service%20-%20Sydjurs.dk/Download.aspx');
77-
77+
7878
$username = variable_get('os2web_cp_service_endpoint_user');
7979
$password = variable_get('os2web_cp_service_endpoint_password');
8080
if (!empty($username) && !empty($password)) {
@@ -912,8 +912,8 @@ function os2web_cp_service_schedule_document_pdf2html_conversion($file_id, $case
912912

913913
/**
914914
* Cron implementation.
915-
* Goes through the enrties in database table,
916-
* downloads the documents as pdf,
915+
* Goes through the enrties in database table,
916+
* downloads the documents as pdf,
917917
* and converts the documents from pdf to html and updates the case metadata field with the document contents.
918918
*
919919
* @return none
@@ -928,7 +928,7 @@ function os2web_cp_service_cron(){
928928
while($record = $result->fetchAssoc()) {
929929
_os2web_cp_service_document_download($record['file_id']);
930930
}
931-
931+
932932
//convert
933933
$query = db_select('os2web_cp_service_documents_conversion', 'dc');
934934
$query->fields('dc',array('file_id', 'filepath_pdf'))
@@ -938,7 +938,7 @@ function os2web_cp_service_cron(){
938938
while($record = $result->fetchAssoc()) {
939939
_os2web_cp_service_document_convert($record['file_id'], $record['filepath_pdf']);
940940
}
941-
941+
942942
//field updating
943943
$query = db_select('os2web_cp_service_documents_conversion', 'dc');
944944
$query->fields('dc',array('file_id', 'case_nid', 'filepath_pdf', 'filepath_html'))
@@ -964,18 +964,18 @@ function os2web_cp_service_cron(){
964964
function _os2web_cp_service_document_download($file_id){
965965
$url = $GLOBALS['base_url'] . '/?q=os2web/service/gf/v1/' . $file_id;//address of remote file
966966
$tmpfname = tempnam(file_directory_temp(), "os2web_cp_document_");//path to where the file will be downloaded
967-
967+
968968
$fp = fopen($tmpfname, 'w');
969-
969+
970970
$ch = curl_init($url);
971971
curl_setopt($ch, CURLOPT_FILE, $fp);
972972
$data= curl_exec($ch);
973-
973+
974974
//Check for 404 (file not found)
975975
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
976976
curl_close($ch);
977977
fclose($fp);
978-
978+
979979
if ($httpCode == 404) {
980980
print_r('404');
981981
db_update('os2web_cp_service_documents_conversion')
@@ -984,7 +984,7 @@ function _os2web_cp_service_document_download($file_id){
984984
))
985985
->condition('file_id', $file_id)
986986
->execute();
987-
} else if ($httpCode == 200) {
987+
} else if ($httpCode == 200) {
988988
db_update('os2web_cp_service_documents_conversion')
989989
->fields(array(
990990
'filepath_pdf' => $tmpfname,
@@ -1068,7 +1068,7 @@ function _os2web_cp_service_update_case_metadata($file_id, $case_nid, $path_to_p
10681068
->execute();
10691069
} else {
10701070
$text = file_get_contents($path_to_html);
1071-
1071+
10721072
//html tags removing
10731073
$text = str_replace('<p>&nbsp;</p>', ' ', $text); //removing unneeded paragraphs
10741074
$text = preg_replace('#<style(.*?)>(.*?)</style>#is', ' ', $text);//removing style tags
@@ -1077,28 +1077,21 @@ function _os2web_cp_service_update_case_metadata($file_id, $case_nid, $path_to_p
10771077
$text = str_replace("\n\r", " ", $text);
10781078
$text = str_replace("\n", " ", $text);
10791079
$text = str_replace("\r", " ", $text);
1080-
1081-
$search_metadata = $case_node->field_os2web_cp_service_searchmt['und'][0]['value'] . $text;
1080+
1081+
$search_metadata = $case_node->field_os2web_cp_service_searchmt['und'][0]['value'] . $text;
10821082
$case_node->field_os2web_cp_service_searchmt['und'][0]['value'] = $search_metadata;
10831083
node_save($case_node);
1084-
1084+
10851085
db_update('os2web_cp_service_documents_conversion')
10861086
->fields(array(
10871087
'status' => 'done',
10881088
))
10891089
->condition('file_id', $file_id)
10901090
->execute();
1091-
1091+
10921092
//tmp files cleanup
10931093
unlink($path_to_html);
10941094
unlink($path_to_pdf);
10951095
}
10961096
}
10971097
}
1098-
1099-
/**
1100-
* Update method installing the module's database without a need to uninstall/install it.
1101-
*/
1102-
function os2web_cp_service_update_7100(){
1103-
drupal_install_schema('os2web_cp_service');
1104-
}

0 commit comments

Comments
 (0)