Skip to content

Commit 2dc7ff7

Browse files
committed
Added post-patches.sh to ensure auto-generation doesn't override proper code for setStartDate() and CustomerProfileExType to be used in UpdateCustomerProfileRequest
1 parent ee1434e commit 2dc7ff7

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

scripts/masterUpdate.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ echo This script will update the generated code
55
echo
66

77
currdir=`pwd`
8-
cmdlist="prepare.sh generateObjectsFromXsd.sh generateControllersFromTemplate.sh appender.sh finish.sh"
8+
# cmdlist="prepare.sh generateObjectsFromXsd.sh generateControllersFromTemplate.sh appender.sh post-patches.sh finish.sh"
9+
cmdlist="generateObjectsFromXsd.sh generateControllersFromTemplate.sh appender.sh finish.sh"
910
for cmd in $cmdlist ; do
1011
echo Executing Script "$cmd"
1112
if [ ! -f $currdir/scripts/$cmd ];then

scripts/post-patches.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Shell file to do post-patches that
2+
# Revert auto-generation (on masterupdate->generateObjectsFromXsd) changes to
3+
# - setStartDate() method in PaymentScheduleType.php
4+
# - CustomerProfileExType gets wrongfully replaced with
5+
# CustomerProfileInfoExType in UpdateCustomerProfileRequest.php
6+
7+
#WORKING --- Remember to escape $ with \$ and replace ' with " and \ with \\ in the replacement expression
8+
#Summary --- Replaces the setStartDate() method with the correct method. To be run in Git Bash or unix shell
9+
#File affected - lib/net/authorize/api/contract/v1/PaymentScheduleType.php
10+
#Run in Git Bash or unix shell
11+
#Assumption - No child code blocks (curly-brace pairs) within the setStartDate method
12+
#Test file - testfile.txt
13+
#Options used:
14+
# -p is used to do replacements. Unlike -n which only traverses the file line by line, but doesn't replace.
15+
# -0777 treats the entire file as a blob, instead of doing line by line
16+
# -i is used only for the final files, when we are sure to do the replace.
17+
# /s at the end of regex does the same thing, called the "single-line" mode
18+
# /g at the end of regex does the replacements for entire file, not just first match
19+
# /i is NOT used in the regex as we want our comparisons to be case-sensitive, not insensitive return/gs' lib/net/authorize/api/contract/v1/testfile.txt
20+
21+
perl -0777 -i -pe 's/\bfunction setStartDate[^}]*return/function setStartDate(\\DateTime \$startDate)
22+
{
23+
\$strDateOnly = \$startDate->format("Y-m-d");
24+
\$this->startDate = \\DateTime::createFromFormat("!Y-m-d", \$strDateOnly);
25+
return/gs' lib/net/authorize/api/contract/v1/PaymentScheduleType.php
26+
git diff -- lib/net/authorize/api/contract/v1/PaymentScheduleType.php
27+
28+
#WORKING --- Remember to escape $ with \$ and replace ' with " and \ with \\
29+
#Summary --- Replaces the CustomerProfileInfoExType with CustomerProfileExType
30+
#Files affected - UpdateCustomerProfileRequest.php
31+
#Run in Git Bash or unix shell
32+
#Assumption - CustomerProfileInfoExType present as a whole word or at starting of a word
33+
#perl -0777 -pe 's/\bCustomerProfileInfoExType/CustomerProfileExType/gs' lib/net/authorize/api/contract/v1/testfile.txt
34+
35+
perl -0777 -i -pe 's/\bCustomerProfileInfoExType/CustomerProfileExType/gs' lib/net/authorize/api/contract/v1/UpdateCustomerProfileRequest.php
36+
git diff -- lib/net/authorize/api/contract/v1/UpdateCustomerProfileRequest.php
37+
38+
##References
39+
# - http://www.rexegg.com/regex-perl-one-liners.html

0 commit comments

Comments
 (0)