Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Quentin CHEVILLON
opacce
Commits
7280cb67
Commit
7280cb67
authored
Jul 23, 2021
by
Patrick Barroca
😁
Browse files
hotline #138070 : fix article indexation on form post
parent
afd13248
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
242 additions
and
29 deletions
+242
-29
VERSIONS_HOTLINE/138070
VERSIONS_HOTLINE/138070
+1
-0
library/Class/Article.php
library/Class/Article.php
+15
-28
library/Class/Date/Iso.php
library/Class/Date/Iso.php
+123
-0
tests/application/modules/admin/controllers/CmsControllerIndexationTest.php
...modules/admin/controllers/CmsControllerIndexationTest.php
+102
-0
tests/scenarios/MultiSelection/MultiSelectionTest.php
tests/scenarios/MultiSelection/MultiSelectionTest.php
+1
-1
No files found.
VERSIONS_HOTLINE/138070
0 → 100644
View file @
7280cb67
- ticket #138070 : Articles : Correction de l'absence de création de la notice correspondante lorsqu'un article indexable était validé
\ No newline at end of file
library/Class/Article.php
View file @
7280cb67
...
...
@@ -1542,10 +1542,19 @@ class Class_Article extends Storm_Model_Abstract {
public
function
updateAttributes
(
Array
$attributes
)
{
unset
(
$attributes
[
'id_items'
]);
foreach
([
'debut'
,
'fin'
,
'events_debut'
,
'events_fin'
]
as
$date_field
)
{
if
(
array_key_exists
(
$date_field
,
$attributes
))
$this
->
$date_field
=
$attributes
[
$date_field
]
=
(
$this
->
_toDate
(
$attributes
[
$date_field
]));
}
$date_iso
=
new
Class_Date_Iso
;
if
(
array_key_exists
(
'debut'
,
$attributes
))
$this
->
debut
=
$attributes
[
'debut'
]
=
$date_iso
->
ensureDate
(
$attributes
[
'debut'
]);
if
(
array_key_exists
(
'fin'
,
$attributes
))
$this
->
fin
=
$attributes
[
'fin'
]
=
$date_iso
->
ensureDate
(
$attributes
[
'fin'
]);
if
(
array_key_exists
(
'events_debut'
,
$attributes
))
$this
->
events_debut
=
$attributes
[
'events_debut'
]
=
$date_iso
->
ensureDateTime
(
$attributes
[
'events_debut'
]);
if
(
array_key_exists
(
'events_fin'
,
$attributes
))
$this
->
events_fin
=
$attributes
[
'events_fin'
]
=
$date_iso
->
ensureDateTime
(
$attributes
[
'events_fin'
]);
$transformer
=
new
Class_CmsUrlTransformer
();
foreach
([
'description'
,
'contenu'
]
as
$content_field
)
{
...
...
@@ -1553,34 +1562,12 @@ class Class_Article extends Storm_Model_Abstract {
$attributes
[
$content_field
]
=
$transformer
->
forSaving
(
$attributes
[
$content_field
]);
}
if
(
isset
(
$attributes
[
'pick_day'
])
&&
is_array
(
$attributes
[
'pick_day'
]))
if
(
isset
(
$attributes
[
'pick_day'
])
&&
is_array
(
$attributes
[
'pick_day'
]))
$attributes
[
'pick_day'
]
=
implode
(
','
,
$attributes
[
'pick_day'
]);
$this
->
old_status
=
$this
->
getStatus
();
parent
::
updateAttributes
(
$attributes
);
return
$this
;
}
protected
function
_toDate
(
$str
)
{
if
(
$str
==
null
||
$str
==
''
)
return
null
;
/** @see http://forge.afi-sa.fr/issues/17968 */
if
(
preg_match
(
'/^(\d{2})\/(\d{2})\/(\d{4})( \d{2}:\d{2})?$/'
,
$str
,
$matches
))
{
$matches
[
4
]
=
isset
(
$matches
[
4
])
?
$matches
[
4
]
:
' 00:00'
;
return
$matches
[
3
]
.
'-'
.
$matches
[
2
]
.
'-'
.
$matches
[
1
]
.
$matches
[
4
];
}
if
(
preg_match
(
'/^(\d{4})-(\d{2})-(\d{2})( \d{2}:\d{2})?/'
,
$str
,
$matches
))
{
$matches
[
4
]
=
isset
(
$matches
[
4
])
?
$matches
[
4
]
:
' 00:00'
;
return
$matches
[
1
]
.
'-'
.
$matches
[
2
]
.
'-'
.
$matches
[
3
]
.
$matches
[
4
];
}
$locale
=
Zend_Registry
::
get
(
'locale'
);
$date
=
new
Zend_Date
(
$str
,
null
,
$locale
);
return
$date
->
toString
(
'YYYY-MM-dd HH:mm'
);
return
parent
::
updateAttributes
(
$attributes
);
}
...
...
library/Class/Date/Iso.php
0 → 100644
View file @
7280cb67
<?php
/**
* Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class
Class_Date_Iso
{
const
DATE_PART_FR
=
'(\d{2})\/(\d{2})\/(\d{4})'
,
DATE_PART_US
=
'(\d{4})-(\d{2})-(\d{2})'
,
TIME_PART
=
'( \d{2}:\d{2})?'
,
DATE_FORMAT
=
'YYYY-MM-dd'
,
TIME_FORMAT
=
' HH:mm'
;
public
function
ensureDate
(
$str
)
{
return
$this
->
ensure
(
$str
);
}
public
function
ensureDateTime
(
$str
)
{
return
(
new
Class_Date_IsoWithTime
)
->
ensure
(
$str
);
}
public
function
ensure
(
$str
)
{
if
(
!
$str
)
return
null
;
/** @see http://forge.afi-sa.fr/issues/17968 */
if
(
$matches
=
$this
->
_match
(
$this
->
_frPattern
(),
$str
))
return
$this
->
_fromFr
(
$matches
);
if
(
$matches
=
$this
->
_match
(
$this
->
_usPattern
(),
$str
))
return
$this
->
_fromUs
(
$matches
);
return
(
$date
=
Class_Date
::
humanDate
(
$str
,
$this
->
_dateFormat
()))
?
$date
:
null
;
}
protected
function
_match
(
$pattern
,
$str
)
{
return
preg_match
(
'/^'
.
$pattern
.
'/'
,
$str
,
$matches
)
?
$matches
:
null
;
}
protected
function
_frPattern
()
{
return
static
::
DATE_PART_FR
;
}
protected
function
_fromFr
(
$matches
)
{
return
$matches
[
3
]
.
'-'
.
$matches
[
2
]
.
'-'
.
$matches
[
1
];
}
protected
function
_usPattern
()
{
return
static
::
DATE_PART_US
;
}
protected
function
_fromUs
(
$matches
)
{
return
$matches
[
1
]
.
'-'
.
$matches
[
2
]
.
'-'
.
$matches
[
3
];
}
protected
function
_dateFormat
()
{
return
static
::
DATE_FORMAT
;
}
}
class
Class_Date_IsoWithTime
extends
Class_Date_Iso
{
protected
function
_frPattern
()
{
return
static
::
DATE_PART_FR
.
static
::
TIME_PART
.
'$'
;
}
protected
function
_fromFr
(
$matches
)
{
return
parent
::
_fromFr
(
$matches
)
.
$this
->
_ensureTime
(
$matches
);
}
protected
function
_usPattern
()
{
return
static
::
DATE_PART_US
.
static
::
TIME_PART
;
}
protected
function
_fromUs
(
$matches
)
{
return
parent
::
_fromUs
(
$matches
)
.
$this
->
_ensureTime
(
$matches
);
}
protected
function
_ensureTime
(
$matches
)
{
return
isset
(
$matches
[
4
])
?
$matches
[
4
]
:
' 00:00'
;
}
protected
function
_dateFormat
()
{
return
static
::
DATE_FORMAT
.
static
::
TIME_FORMAT
;
}
}
tests/application/modules/admin/controllers/CmsControllerIndexationTest.php
0 → 100644
View file @
7280cb67
<?php
/**
* Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
abstract
class
CmsControllerIndexationPostTestCase
extends
Admin_AbstractControllerTestCase
{
protected
$_storm_default_to_volatile
=
true
;
public
function
setUp
()
{
parent
::
setUp
();
Class_AdminVar
::
set
(
'WORKFLOW'
,
1
);
$this
->
fixture
(
Class_ArticleCategorie
::
class
,
[
'id'
=>
1
,
'libelle'
=>
'Category'
]);
$this
->
fixture
(
Class_Article
::
class
,
[
'id'
=>
1
,
'id_cat'
=>
1
,
'titre'
=>
'un titre'
,
'contenu'
=>
'un contenu'
,
'status'
=>
Class_Article
::
STATUS_VALIDATION_PENDING
]);
Class_Article
::
setTimeSource
(
new
TimeSourceForTest
(
'2021-07-23 11:17:07'
));
}
public
function
tearDown
()
{
Class_Article
::
setTimeSource
(
null
);
parent
::
tearDown
();
}
protected
function
_postWith
(
$datas
)
{
$this
->
postDispatch
(
'/admin/cms/edit/id/1'
,
array_merge
([
'titre'
=>
'un titre'
,
'cacher_titre'
=>
'0'
,
'id_cat'
=>
'1'
,
'status'
=>
Class_Article
::
STATUS_VALIDATION_PENDING
,
'debut'
=>
'23/07/2021'
,
'fin'
=>
''
,
'events_debut'
=>
'23/07/2021'
,
'events_fin'
=>
'23/07/2021'
,
'all_day'
=>
'1'
,
'id_lieu'
=>
'0'
,
'avis'
=>
'0'
,
'contenu'
=>
'un contenu'
,
'description'
=>
''
,
'tags'
=>
''
,
'indexation'
=>
'1'
,
'domaine_ids'
=>
''
],
$datas
));
}
}
class
CmsControllerIndexationPostNotVisibleByStatusTest
extends
CmsControllerIndexationPostTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
_postWith
([]);
}
/** @test */
public
function
articleShouldNotBeIndexed
()
{
$this
->
assertNull
(
Class_Notice
::
findFirstBy
([]));
}
}
class
CmsControllerIndexationPostVisibleByStatusTest
extends
CmsControllerIndexationPostTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
_postWith
([
'status'
=>
Class_Article
::
STATUS_VALIDATED
]);
}
/** @test */
public
function
articleShouldBeIndexed
()
{
$this
->
assertNotNull
(
Class_Notice
::
findFirstBy
([]));
}
}
tests/scenarios/MultiSelection/MultiSelectionTest.php
View file @
7280cb67
...
...
@@ -493,7 +493,7 @@ class MultiSelectionArticlesPostDatasTest extends MultiSelectionArticlesPostTest
/** @test */
public
function
publicationShouldNotBeModified
()
{
$this
->
assertEquals
(
'2011-03-20
00:00
'
,
$this
->
concert
->
getDebut
());
$this
->
assertEquals
(
'2011-03-20'
,
$this
->
concert
->
getDebut
());
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment