|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/** |
|
3
|
|
|
* migrate |
|
4
|
|
|
* |
|
5
|
|
|
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED |
|
6
|
|
|
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK. |
|
7
|
|
|
* |
|
8
|
|
|
* Permission is hereby granted to use or copy this program |
|
9
|
|
|
* for any purpose, provided the above notices are retained on all copies. |
|
10
|
|
|
* Permission to modify the code and to distribute modified code is granted, |
|
11
|
|
|
* provided the above notices are retained, and a notice that the code was |
|
12
|
|
|
* modified is included with the above copyright notice. |
|
13
|
|
|
* |
|
14
|
|
|
* @category Wp |
|
15
|
|
|
* @package Punction |
|
16
|
|
|
* @author Andrzej Marcinkowski <[email protected]> |
|
17
|
|
|
* @copyright 2014 Wojewódzki Szpital Zespolony, Kalisz |
|
18
|
|
|
* @license MIT http://opensource.org/licenses/MIT |
|
19
|
|
|
* @version 1.0 $Id$ $Format:%H$ |
|
20
|
|
|
* @link http:// |
|
21
|
|
|
* @since File available since Release 1.0.0 |
|
22
|
|
|
* PHP Version 5 |
|
23
|
|
|
*/ |
|
24
|
|
|
use Hospitalplugin\Entities\PatientZZ; |
|
25
|
|
|
use Punction\DB\DoctrineBootstrap; |
|
26
|
|
|
|
|
27
|
|
|
if (! defined ( 'ABSPATH' )) { |
|
28
|
|
|
define ( 'WP_USE_THEMES', false ); |
|
29
|
|
|
require ('/var/www/wp/wp-load.php'); |
|
30
|
|
|
} |
|
31
|
|
|
require_once ('/var/www/vendor/autoload.php'); |
|
32
|
|
|
Logger::configure ( '../resources/log4php.xml' ); |
|
33
|
|
|
/** |
|
34
|
|
|
* migration log4php logger |
|
35
|
|
|
*/ |
|
36
|
|
|
$log = Logger::getLogger ( "migration" ); |
|
37
|
|
|
$log->info ( "Start!" ); |
|
38
|
|
|
|
|
39
|
|
|
global $wpdb; |
|
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
*/ |
|
42
|
|
|
$query = " |
|
43
|
|
|
SELECT |
|
44
|
|
|
* |
|
45
|
|
|
FROM $wpdb->posts |
|
46
|
|
|
WHERE |
|
47
|
|
|
post_type = 'pacjent' |
|
48
|
|
|
AND post_status = 'publish' |
|
49
|
|
|
ORDER BY |
|
50
|
|
|
post_title, |
|
51
|
|
|
post_date |
|
52
|
|
|
LIMIT |
|
53
|
|
|
35000"; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
*/ |
|
57
|
|
|
$error = "Error: the query failed..."; |
|
58
|
|
|
/** |
|
59
|
|
|
*/ |
|
60
|
|
|
$results = $wpdb->get_results ( $query, ARRAY_A ) || wp_die ( $error ); |
|
61
|
|
|
|
|
62
|
|
|
$db1 = new DoctrineBootstrap (); |
|
63
|
|
|
$entityManager = $db1->getEntityManager (); |
|
64
|
|
|
|
|
65
|
|
|
foreach ( $results as $result ) { |
|
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
*/ |
|
68
|
|
|
$id = $result ['ID']; |
|
69
|
|
|
/** |
|
70
|
|
|
*/ |
|
71
|
|
|
$title = $result ['post_title']; |
|
72
|
|
|
/** |
|
73
|
|
|
*/ |
|
74
|
|
|
$pesel = implode ( get_post_meta ( $id, 'pesel' ) ); |
|
75
|
|
|
/** |
|
76
|
|
|
*/ |
|
77
|
|
|
$oddzid = implode ( get_post_meta ( $id, 'oddzial.ID' ) ); |
|
78
|
|
|
/** |
|
79
|
|
|
*/ |
|
80
|
|
|
|
|
81
|
|
|
$numer_historii = implode ( get_post_meta ( $id, 'numer_ksiegi_glownej' ) ); |
|
82
|
|
|
/** |
|
83
|
|
|
*/ |
|
84
|
|
|
$data_kategoryzacji = implode ( get_post_meta ( $id, 'data_kategoryzacji' ) ); |
|
85
|
|
|
/** |
|
86
|
|
|
*/ |
|
87
|
|
|
$kategoria_pacjenta = implode ( get_post_meta ( $id, 'kategoria_pacjenta' ) ); |
|
88
|
|
|
/** |
|
89
|
|
|
*/ |
|
90
|
|
|
$aktywnosc_fizyczna = implode ( get_post_meta ( $id, '1_aktywnosc_fizyczna' ) ); |
|
91
|
|
|
/** |
|
92
|
|
|
*/ |
|
93
|
|
|
$higiena = implode ( get_post_meta ( $id, '2_higiena' ) ); |
|
94
|
|
|
/** |
|
95
|
|
|
*/ |
|
96
|
|
|
$odzywianie = implode ( get_post_meta ( $id, '3_odzywianie' ) ); |
|
97
|
|
|
/** |
|
98
|
|
|
*/ |
|
99
|
|
|
$wydalanie = implode ( get_post_meta ( $id, '4_wydalanie' ) ); |
|
100
|
|
|
/** |
|
101
|
|
|
*/ |
|
102
|
|
|
$pomiar_objawow_zyciowych = implode ( get_post_meta ( $id, '5_pomiar_objawow_zyciowych' ) ); |
|
103
|
|
|
/** |
|
104
|
|
|
*/ |
|
105
|
|
|
$leczenie = implode ( get_post_meta ( $id, '6_leczenie' ) ); |
|
106
|
|
|
/** |
|
107
|
|
|
*/ |
|
108
|
|
|
$edukacja_i_wsparcie_psychiczne = implode ( get_post_meta ( $id, '7_edukacja_i_wsparcie_psychiczne' ) ); |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
*/ |
|
112
|
|
|
$patient = new PatientZZ (); |
|
|
|
|
|
|
113
|
|
|
$patient->setName ( $title ); |
|
114
|
|
|
if ($data_kategoryzacji == null) { |
|
115
|
|
|
$log->warn ( "Patient " . $id . " missing date. Omitting." ); |
|
116
|
|
|
continue; |
|
117
|
|
|
} |
|
118
|
|
|
$patient->setDataKategoryzacji ( \DateTime::createFromFormat ( "d-m-Y", $data_kategoryzacji ) ); |
|
119
|
|
|
$patient->setOddzialId ( $oddzid ); |
|
120
|
|
|
$patient->setNumerHistorii ( $numer_historii ); |
|
121
|
|
|
|
|
122
|
|
|
$patient->setPesel ( $pesel ); |
|
123
|
|
|
$patient->setKategoriaPacjenta ( $kategoria_pacjenta ); |
|
124
|
|
|
$patient->setAktywnoscFizyczna ( $aktywnosc_fizyczna ); |
|
125
|
|
|
$patient->setHigiena ( $higiena ); |
|
126
|
|
|
$patient->setOdzywianie ( $odzywianie ); |
|
127
|
|
|
$patient->setWydalanie ( $wydalanie ); |
|
128
|
|
|
$patient->setPomiarObjawowZyciowych ( $pomiar_objawow_zyciowych ); |
|
129
|
|
|
$patient->setLeczenie ( $leczenie ); |
|
130
|
|
|
$patient->setEdukacjaIWsparciePsychiczne ( $edukacja_i_wsparcie_psychiczne ); |
|
131
|
|
|
|
|
132
|
|
|
$entityManager->persist ( $patient ); |
|
133
|
|
|
} |
|
134
|
|
|
$entityManager->flush (); |
|
135
|
|
|
$log->info ( "Stop!" ); |
|
136
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.