10 include_once (
'FDL/Class.Doc.php');
11 include_once (
"FDL/Lib.Dir.php");
14 define(
"REDCOLOR",
"\033" .
'[01;31m');
15 define(
"GREENCOLOR",
"\033" .
'[01;32m');
16 define(
"STOPCOLOR",
"\033" .
'[0m');
20 $usage->setDefinitionText(
"Update date from french to iso");
21 $force = (
$usage->addOptionalParameter(
"force",
"force conversion although the configuration is good", array(
34 simpleQuery(
$action->dbaccess,
"SELECT current_database();", $databaseName,
true,
true);
37 print "Database '$databaseName' datestyle is 'ISO, DMY'.\n\tDatabase is clean.\n";
38 print "Inspect family parameters and default values only.\n";
43 if ((
$force) || ($dbDate ==
"SQL, DMY" &&
$locale ==
"dmy")) {
45 print "Database datestyle is 'SQL, DMY'.\nDatabase '$databaseName' needs to be migrated\n";
47 print "Force mode enable.\n";
49 print "Conversion dates to iso starts ...\n";
56 $err = sprintf(
"Wrong Config Date detected : CORE_LCDATE= '%s', database datestyle='%s'\n",
$locale, $dbDate);
66 $sql =
"SELECT a1.id, a1.docid, a1.type from docattr a1, docattr a2 where a1.usefor != 'Q' and (a1.type ~ 'date' or a1.type ~ 'timestamp') and a1.frameid=a2.id and a2.type ~ 'array' and a1.id !~ ':';";
71 foreach ($res as $attr) {
74 $attrName = pg_escape_string($attr[
"id"]);
76 $sql = sprintf(
"select count(%s) from doc%d where %s ~ '/';", $attrName,
$famid, $attrName);
79 printf(
"Family %s - Attribute %s : %d documents to %supdate%s\n", $famName, $attrName, $count,
REDCOLOR,
STOPCOLOR);
85 $b1 = microtime(
true);
86 $sql = sprintf(
"UPDATE doc%d set %s=regexp_replace(%s, E'(..)/(..)/(....)', E'\\\\3-\\\\2-\\\\1','g') where %s ~ '/';",
$famid, $attrName, $attrName, $attrName);
89 $partDelay = microtime(
true) - $b1;
90 printf(
"\t%s updated in %ds.\n", $attrName, $partDelay);
95 simpleQuery($action->dbaccess,
"SELECT current_database();", $databaseName,
true,
true);
96 $sql = sprintf(
"ALTER DATABASE %s set datestyle = 'ISO, DMY'", pg_escape_identifier($databaseName));
98 print "Change database datestyle to 'ISO, DMY'\n";
99 $sql =
"update paramv set val='iso' where name = 'CORE_LCDATE'";
101 print "Change CORE_LCDATE to 'iso'\n";
103 $e = microtime(
true) - $b;
104 printf(
"End of conversion in %dmin %ds.\n", $e / 60, $e % 60);
114 $b = microtime(
true);
116 $s->setObjectReturn(
true);
117 $s->addFilter(
"param ~ E'([0-9]{2})/([0-9]{2})/([0-9]{4})' or defval ~ E'([0-9]{2})/([0-9]{2})/([0-9]{4})'");
120 if (
$s->count() == 0) {
121 print "\tFamily parameters and default date are clean.\n";
127 while ($docfam =
$s->getNextDoc()) {
128 $defVal = $docfam->getOwnDefValues();
129 $params = $docfam->getOwnParams();
130 $la = $docfam->getAttributes();
131 foreach (
$la as $attrid => $oAttr) {
133 if ($oAttr->type ==
"date" || $oAttr->type ==
"timestamp") {
135 if (!empty($defVal[$attrid])) {
136 $date = $defVal[$attrid];
138 $isoDate = preg_replace(
'/(..)\/(..)\/(....)/',
'$3-$2-$1', $date);
139 if ($isoDate != $date) {
140 $docfam->setDefValue($attrid, $isoDate);
142 print "\tChange default value for $attrid : $date to $isoDate\n";
144 $err = $docfam->modify();
148 printf(
"\t%s updated.\n", $attrid);
153 if ($oAttr->usefor ==
"Q") {
154 if (!empty($params[$attrid])) {
155 $date = $params[$attrid];
157 $isoDate = preg_replace(
'/(..)\/(..)\/(....)/',
'$3-$2-$1', $date);
158 if ($isoDate != $date) {
159 $docfam->setParam($attrid, $isoDate);
160 print "\tChange parameter value for $attrid : $date to $isoDate\n";
162 $err = $docfam->modify();
166 printf(
"\t%s updated.\n", $attrid);
176 $e = microtime(
true) - $b;
177 printf(
"Family parameters and default date conversion in %dmin %ds.\n", $e / 60, $e % 60);
convertFamilyDateToIso(Action $action, $onlyAnalyze=false)
getParam($name, $def="")
must be in core or global type
convertDateToIso(Action $action, $onlyAnalyze=false)
getNameFromId($dbaccess, $id)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
if($file) if($subject==""&&$file) if($subject=="") $err
Verify arguments for wsh programs.