Last active
August 29, 2016 19:40
-
-
Save jhoffmann/b422060b0dd61c2eea34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eu | |
if [ -d cache -a -O cache ]; then | |
if [ `hostname -s` == 'si-admin' ]; then | |
# send api call to newrelic | |
fi | |
else | |
echo "Either wrong path (not sugar root) or wrong user (run as the owner of the cache folder)" | |
exit | |
fi | |
DO_REPAIR=1 | |
DO_API=1 | |
for arg in "$@"; do | |
case "$arg" in | |
-skiprr) DO_REPAIR=0 | |
;; | |
-skipapi) DO_API=0 | |
;; | |
esac | |
done | |
if [[ $DO_REPAIR > 0 ]]; then | |
php << 'SCRIPT' | |
<?php | |
echo "Initializing environment ...".PHP_EOL; | |
if(is_file('config.php')) | |
require_once('config.php'); | |
if(is_file('config_override.php')) | |
require_once('config_override.php'); | |
$newCacheDir = '/tmp/cache'; | |
@mkdir($newCacheDir); | |
$GLOBALS['sugar_config']['cache_dir'] = $newCacheDir; | |
define('sugarEntry', true); | |
require_once ('include/entryPoint.php'); | |
require_once ('modules/Administration/QuickRepairAndRebuild.php'); | |
$user = new User(); | |
$GLOBALS['current_user'] = $user->getSystemUser(); | |
echo "Running a quick repair and rebuild ...".PHP_EOL; | |
$rc = new RepairAndClear(); | |
$rc->repairAndClearAll(array('clearAll'), array(translate('LBL_ALL_MODULES')), false, false, ''); | |
echo "Copying files into place ...".PHP_EOL; | |
SCRIPT | |
for i in /tmp/cache/api/metadata/* | |
do | |
sed -i 's|/tmp/||' $i | |
done | |
rsync -aW --delay-updates /tmp/cache/ ./cache && rm -rf /tmp/cache/ | |
fi | |
if [[ $DO_API > 0 ]]; then | |
php << 'SCRIPT' | |
<?php | |
echo "Initializing environment for API cache generation ...".PHP_EOL; | |
define('sugarEntry', true); | |
require_once ('include/entryPoint.php'); | |
# 7.6 and above store their metadata in the db, fix the /tmp/cache file paths | |
class CustomMetaDataManager extends MetaDataManager { | |
function fixHashValues() { | |
# Make sure we don't barf if run on a 7.5 instance | |
if (method_exists($this, 'getFromCacheTable')) { | |
echo "Updating the metadata hash paths ...".PHP_EOL; | |
foreach ($this->getFromCacheTable('hashes') as $k => $v) | |
$hashes[str_replace('/tmp/', '', $k)] = $v; | |
$this->storeToCacheTable('hashes', $hashes); | |
} | |
} | |
} | |
# Set to developer mode, so we ignore cached data during regeneration | |
$GLOBALS['sugar_config']['developerMode'] = 1; | |
echo "Rebuilding the Public API data ...".PHP_EOL; | |
$mm = CustomMetaDataManager::getManager('base', true, true); | |
$data = $mm->getMetadata(); | |
$user = new User(); | |
$GLOBALS['current_user'] = $user->getSystemUser(); | |
$context = new MetaDataContextUser($user); | |
echo "Rebuilding the Private API data ...".PHP_EOL; | |
$mm = CustomMetaDataManager::getManager('base', false, true); | |
$data = $mm->getMetadata(array(), $context); | |
echo "Rebuilding the Language API data ...".PHP_EOL; | |
$mm->getLanguage(array('lang' => 'en_us', 'ordered' => true)); | |
$mm->fixHashValues(); | |
SCRIPT | |
fi |
Hashes also exist for the language files, which end up looking like:
hashes
array(4) {
'meta_hash_public_base' => string(32) "aecef60cf035b512e0bb0e68aaa7b895"
'/tmp/cache/api/metadata/lang_en_us_base_public.json' => string(32) "638a68ea5afcd5608d13e19be5d930aa"
'meta_hash_d394914f5c4e9efa1246a71b7f1ee208_base' => string(32) "5a7cdacbea866a8e3a54781e8fe9762f"
'/tmp/cache/api/metadata/lang_en_us_base_ordered.json' => string(32) "f2f87d4e09e2138cd2503b79757465d9"
}
before the key translation is done.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So what is going on here with the key containing /tmp/ ? The keys are based on platforms/metadata contexts, not file paths. There should be no way that /tmp/ is ever in the key.