Skip to content

Commit a2da5e9

Browse files
committed
Added ability to specify destination
1 parent df12c74 commit a2da5e9

3 files changed

Lines changed: 223 additions & 5 deletions

File tree

patch.sh

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
#!/bin/bash
2+
# Patch apllying tool template
3+
# v0.1.2
4+
# (c) Copyright 2013. Magento Inc.
5+
#
6+
# DO NOT CHANGE ANY LINE IN THIS FILE.
7+
8+
# 1. Check required system tools
9+
_check_installed_tools() {
10+
local missed=""
11+
12+
until [ -z "$1" ]; do
13+
type -t $1 >/dev/null 2>/dev/null
14+
if (( $? != 0 )); then
15+
missed="$missed $1"
16+
fi
17+
shift
18+
done
19+
20+
echo $missed
21+
}
22+
23+
REQUIRED_UTILS='sed patch'
24+
MISSED_REQUIRED_TOOLS=`_check_installed_tools $REQUIRED_UTILS`
25+
if (( `echo $MISSED_REQUIRED_TOOLS | wc -w` > 0 ));
26+
then
27+
echo -e "Error! Some required system tools, that are utilized in this sh script, are not installed:\nTool(s) \"$MISSED_REQUIRED_TOOLS\" is(are) missed, please install it(them)."
28+
exit 1
29+
fi
30+
31+
# 2. Determine bin path for system tools
32+
CAT_BIN=`which cat`
33+
PATCH_BIN=`which patch`
34+
SED_BIN=`which sed`
35+
PWD_BIN=`which pwd`
36+
BASENAME_BIN=`which basename`
37+
38+
BASE_NAME=`$BASENAME_BIN "$0"`
39+
40+
# 3. Help menu
41+
if [ "$1" = "-?" -o "$1" = "-h" -o "$1" = "--help" ]
42+
then
43+
$CAT_BIN << EOFH
44+
Usage: sh $BASE_NAME [--help] [-R|--revert] [--list]
45+
Apply embedded patch.
46+
47+
-R, --revert Revert previously applied embedded patch
48+
--list Show list of applied patches
49+
--help Show this help message
50+
EOFH
51+
exit 0
52+
fi
53+
54+
# 4. Get "revert" flag and "list applied patches" flag
55+
REVERT_FLAG=
56+
SHOW_APPLIED_LIST=0
57+
if [ "$1" = "-R" -o "$1" = "--revert" ]
58+
then
59+
REVERT_FLAG=-R
60+
fi
61+
if [ "$1" = "--list" ]
62+
then
63+
SHOW_APPLIED_LIST=1
64+
fi
65+
66+
# 5. File pathes
67+
CURRENT_DIR=`$PWD_BIN`/
68+
APP_ETC_DIR=`echo "$CURRENT_DIR""app/etc/"`
69+
APPLIED_PATCHES_LIST_FILE=`echo "$APP_ETC_DIR""applied.patches.list"`
70+
71+
# 6. Show applied patches list if requested
72+
if [ "$SHOW_APPLIED_LIST" -eq 1 ] ; then
73+
echo -e "Applied/reverted patches list:"
74+
if [ -e "$APPLIED_PATCHES_LIST_FILE" ]
75+
then
76+
if [ ! -r "$APPLIED_PATCHES_LIST_FILE" ]
77+
then
78+
echo "ERROR: \"$APPLIED_PATCHES_LIST_FILE\" must be readable so applied patches list can be shown."
79+
exit 1
80+
else
81+
$SED_BIN -n "/SUP-\|SUPEE-/p" $APPLIED_PATCHES_LIST_FILE
82+
fi
83+
else
84+
echo "<empty>"
85+
fi
86+
exit 0
87+
fi
88+
89+
# 7. Check applied patches track file and its directory
90+
_check_files() {
91+
if [ ! -e "$APP_ETC_DIR" ]
92+
then
93+
echo "ERROR: \"$APP_ETC_DIR\" must exist for proper tool work."
94+
exit 1
95+
fi
96+
97+
if [ ! -w "$APP_ETC_DIR" ]
98+
then
99+
echo "ERROR: \"$APP_ETC_DIR\" must be writeable for proper tool work."
100+
exit 1
101+
fi
102+
103+
if [ -e "$APPLIED_PATCHES_LIST_FILE" ]
104+
then
105+
if [ ! -w "$APPLIED_PATCHES_LIST_FILE" ]
106+
then
107+
echo "ERROR: \"$APPLIED_PATCHES_LIST_FILE\" must be writeable for proper tool work."
108+
exit 1
109+
fi
110+
fi
111+
}
112+
113+
_check_files
114+
115+
# 8. Apply/revert patch
116+
# Note: there is no need to check files permissions for files to be patched.
117+
# "patch" tool will not modify any file if there is not enough permissions for all files to be modified.
118+
# Get start points for additional information and patch data
119+
SKIP_LINES=$((`$SED_BIN -n "/^__PATCHFILE_FOLLOWS__$/=" "$CURRENT_DIR""$BASE_NAME"` + 1))
120+
ADDITIONAL_INFO_LINE=$(($SKIP_LINES - 3))p
121+
122+
_apply_revert_patch() {
123+
DRY_RUN_FLAG=
124+
if [ "$1" = "dry-run" ]
125+
then
126+
DRY_RUN_FLAG=" --dry-run"
127+
echo "Checking if patch can be applied/reverted successfully..."
128+
fi
129+
PATCH_APPLY_REVERT_RESULT=`$SED_BIN -e '1,/^__PATCHFILE_FOLLOWS__$/d' "$CURRENT_DIR""$BASE_NAME" | $PATCH_BIN $DRY_RUN_FLAG $REVERT_FLAG -p0`
130+
PATCH_APPLY_REVERT_STATUS=$?
131+
if [ $PATCH_APPLY_REVERT_STATUS -eq 1 ] ; then
132+
echo -e "ERROR: Patch can't be applied/reverted successfully.\n\n$PATCH_APPLY_REVERT_RESULT"
133+
exit 1
134+
fi
135+
if [ $PATCH_APPLY_REVERT_STATUS -eq 2 ] ; then
136+
echo -e "ERROR: Patch can't be applied/reverted successfully."
137+
exit 2
138+
fi
139+
}
140+
141+
REVERTED_PATCH_MARK=
142+
if [ -n "$REVERT_FLAG" ]
143+
then
144+
REVERTED_PATCH_MARK=" | REVERTED"
145+
fi
146+
147+
_apply_revert_patch dry-run
148+
_apply_revert_patch
149+
150+
# 9. Track patch applying result
151+
echo "Patch was applied/reverted successfully."
152+
ADDITIONAL_INFO=`$SED_BIN -n ""$ADDITIONAL_INFO_LINE"" "$CURRENT_DIR""$BASE_NAME"`
153+
APPLIED_REVERTED_ON_DATE=`date -u +"%F %T UTC"`
154+
APPLIED_REVERTED_PATCH_INFO=`echo -n "$APPLIED_REVERTED_ON_DATE"" | ""$ADDITIONAL_INFO""$REVERTED_PATCH_MARK"`
155+
echo -e "$APPLIED_REVERTED_PATCH_INFO\n$PATCH_APPLY_REVERT_RESULT\n\n" >> "$APPLIED_PATCHES_LIST_FILE"
156+
157+
exit 0
158+
159+
160+
SUPEE-1533 | EE_1.10.0.0 | v1 | _ | n/a | SUPEE-1533_EE_1.10.0.0_v1.patch
161+
162+
__PATCHFILE_FOLLOWS__
163+
diff --git app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php
164+
index 86a0645..25847dd 100644
165+
--- app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php
166+
+++ app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php
167+
@@ -339,7 +339,7 @@ class Mage_Adminhtml_Block_Dashboard_Graph extends Mage_Adminhtml_Block_Dashboar
168+
}
169+
return self::API_URL . '?' . implode('&', $p);
170+
} else {
171+
- $gaData = urlencode(base64_encode(serialize($params)));
172+
+ $gaData = urlencode(base64_encode(json_encode($params)));
173+
$gaHash = Mage::helper('adminhtml/dashboard_data')->getChartDataHash($gaData);
174+
$params = array('ga' => $gaData, 'h' => $gaHash);
175+
return $this->getUrl('*/*/tunnel', array('_query' => $params));
176+
diff --git app/code/core/Mage/Adminhtml/controllers/DashboardController.php app/code/core/Mage/Adminhtml/controllers/DashboardController.php
177+
index ca0f179..34eed31 100644
178+
--- app/code/core/Mage/Adminhtml/controllers/DashboardController.php
179+
+++ app/code/core/Mage/Adminhtml/controllers/DashboardController.php
180+
@@ -77,7 +77,8 @@ class Mage_Adminhtml_DashboardController extends Mage_Adminhtml_Controller_Actio
181+
if ($gaData && $gaHash) {
182+
$newHash = Mage::helper('adminhtml/dashboard_data')->getChartDataHash($gaData);
183+
if ($newHash == $gaHash) {
184+
- if ($params = unserialize(base64_decode(urldecode($gaData)))) {
185+
+ $params = json_decode(base64_decode(urldecode($gaData)), true);
186+
+ if ($params) {
187+
$response = $httpClient->setUri(Mage_Adminhtml_Block_Dashboard_Graph::API_URL)
188+
->setParameterGet($params)
189+
->setConfig(array('timeout' => 5))
190+

src/MageDownload/Command/DownloadCommand.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ protected function configure()
4545
'file',
4646
InputArgument::REQUIRED,
4747
'The file to download'
48+
)
49+
->addArgument(
50+
'destination',
51+
InputArgument::OPTIONAL,
52+
'The destination where the file should be downloaded'
4853
);
4954
parent::configure();
5055
}
@@ -60,17 +65,40 @@ protected function configure()
6065
protected function execute(InputInterface $input, OutputInterface $output)
6166
{
6267
$download = new Download;
63-
$file = $input->getArgument('file');
6468
$result = $download->get(
65-
$file,
69+
$input->getArgument('file'),
6670
$this->getAccountId($input),
6771
$this->getAccessToken($input)
6872
);
69-
$success = file_put_contents(getcwd() . DIRECTORY_SEPARATOR . $file, $result);
73+
$destination = $this->getDestination($input);
74+
$output->writeln(sprintf('Downloading to <info>%s</info>...', $destination));
75+
$success = file_put_contents($destination, $result);
7076
if ($success) {
71-
$output->writeln(sprintf('File saved to <info>%s</info>', $file));
77+
$output->writeln('Complete');
7278
} else {
7379
$output->writeln('<error>Failed to download file</error>');
7480
}
7581
}
82+
83+
/**
84+
* Determine where the file should download to
85+
*
86+
* @param InputInterface $input
87+
*
88+
* @return string
89+
*/
90+
private function getDestination(InputInterface $input)
91+
{
92+
$dest = $input->getArgument('destination');
93+
if (!$dest) {
94+
return getcwd() . DIRECTORY_SEPARATOR . $input->getArgument('file');
95+
}
96+
if (is_dir($dest)) {
97+
if (substr($dest, -1) !== '/') {
98+
$dest .= DIRECTORY_SEPARATOR;
99+
}
100+
return $dest . $input->getArgument('file');
101+
}
102+
return $dest;
103+
}
76104
}

src/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use MageDownload\Command\InfoCommand;
1919
use Symfony\Component\Console\Application;
2020

21-
$app = new Application('Magedownload CLI', '1.0.0');
21+
$app = new Application('Magedownload CLI', '1.0.1');
2222

2323
$app->add(new DownloadCommand);
2424
$app->add(new InfoCommand);

0 commit comments

Comments
 (0)