public function run($request)
 {
     $strCSVPath = CONTINENTAL_CONTENT_PATH . '/code/ThirdParty/IP2LOCATION-DB.CSV';
     if (!file_exists($strCSVPath)) {
         echo "<p>I cant find the IP2LOCATION-DB.CSV file to import any data.<br>\n\t\t\t\tPlease download DB3.LITE database from <a href='http://lite.ip2location.com/'>http://lite.ip2location.com/</a>.<br>\n\t\t\t\tNOTE: It's adviced to edit the DB to only include the countries you want to handle, it contains 2 million records!!!<br>\n\t\t\t\tOr make a CSV contain these columns<br>\n\t\t\t\t`IPFrom`,`IPTo`,`Country`,`CountryName`,`Region`,`City`\n\t\t\t\t</p>";
     } else {
         if (!isset($_REQUEST['confirm'])) {
             $strLink = Director::baseURL() . 'dev/tasks/ImportIPToLocationTask?confirm=1';
             echo "<p>CAUTION!!!<br>\n\t\t\t\t\tPlease confirm your action<br>\n\t\t\t\t\t<a href='{$strLink}'>I confirm the action</a><br>\n\t\t\t\t\t<a href='{$strLink}&emptydb=1'>I confirm the action, please empty the DB before you import</a>\n\t\t\t\t\t</p>";
         } else {
             increase_time_limit_to();
             if (isset($_REQUEST['emptydb'])) {
                 DB::query('TRUNCATE `IpToLocation`;');
             }
             $arrFields = array_keys(Config::inst()->get('IpToLocation', 'db'));
             $handle = fopen($strCSVPath, "r");
             if ($handle) {
                 while (($line = fgets($handle)) !== false) {
                     $line = str_replace('","', '___', $line);
                     $line = str_replace('"', '', $line);
                     $arrParts = Convert::raw2sql(explode("___", $line));
                     unset($arrParts[3]);
                     DB::query('INSERT INTO `IpToLocation` (`' . implode('`,`', $arrFields) . '`) VALUES (\'' . implode('\',\'', $arrParts) . '\')');
                 }
                 fclose($handle);
             } else {
                 echo 'Error opening file';
             }
         }
     }
 }
 function run($request)
 {
     increase_time_limit_to(3600);
     $gitUser = $this->Config()->get("git_user_name");
     $packagistUser = $this->Config()->get("git_user_name");
     if ($gitUser && $packagistUser) {
         //all is good ...
     } else {
         user_error("make sure to set your git and packagist usernames via the standard config system");
     }
     $count = 0;
     $this->getAllRepos();
     echo "<h1>Testing " . count(self::$modules) . " modules (git user: {$gitUser} and packagist user: {$packagistUser}) ...</h1>";
     $methodsToCheck = $this->Config()->get("methods_to_check");
     foreach (self::$modules as $module) {
         $count++;
         $failures = 0;
         echo "<h3><a href=\"https://github.com/" . $gitUser . "/silverstripe-" . $module . "\"></a>{$count}. checking {$module}</h3>";
         foreach ($methodsToCheck as $method) {
             if (!$this->{$method}($module)) {
                 $failures++;
                 DB::alteration_message("bad response for {$method}", "deleted");
             }
         }
         if ($failures == 0) {
             DB::alteration_message("OK", "created");
         }
         ob_flush();
         flush();
     }
     echo "----------------------------- THE END --------------------------";
 }
 /**
  * This is the main method to build the master string tables with the original strings.
  * It will search for existent modules that use the i18n feature, parse the _t() calls
  * and write the resultant files in the lang folder of each module.
  * 
  * @uses DataObject->collectI18nStatics()
  */
 public function run($request)
 {
     increase_time_limit_to();
     $c = new i18nTextCollector();
     $restrictModules = $request->getVar('module') ? explode(',', $request->getVar('module')) : null;
     return $c->run($restrictModules);
 }
 /**
  * 
  * @param SS_HTTPRequest $request
  */
 public function run($request)
 {
     increase_time_limit_to();
     echo 'Pass ?refresh=1 to refresh your members<br/>';
     echo '<hr/>';
     $refresh = $request->getVar('refresh');
     if ($refresh) {
         DB::alteration_message("Resetting all members location");
         DB::query('UPDATE Member SET Latitude = 0, Longitude = 0');
     }
     $Members = Member::get()->filter(array('Latitude' => 0));
     foreach ($Members as $Member) {
         DB::alteration_message('Processing member #' . $Member->ID . ' - ' . $Member->getTitle());
         if (!$Member->Latitude) {
             if ($Member->canBeGeolocalized()) {
                 DB::alteration_message($Member->GeocodeText());
                 if (!$Member->CountryCode) {
                     DB::alteration_message("Warning ! This member has no country code", "error");
                 }
                 /* @var $res Geocoder\Model\Address */
                 $res = $Member->Geocode();
                 if ($res) {
                     DB::alteration_message('Geocode success on ' . $res->getLatitude() . ',' . $res->getLongitude() . ' : ' . $res->getStreetNumber() . ', ' . $res->getStreetName() . ' ' . $res->getPostalCode() . ' ' . $res->getLocality() . ' ' . $res->getCountry(), 'created');
                     $Member->write();
                 } else {
                     DB::alteration_message('Geocode error', 'error');
                 }
             } else {
                 DB::alteration_message('Cannot be geolocalized', 'error');
             }
         } else {
             DB::alteration_message('Already geolocalized', 'error');
         }
     }
 }
Example #5
0
 function __construct($filename = null)
 {
     // If we're working with image resampling, things could take a while.  Bump up the time-limit
     increase_time_limit_to(300);
     if ($filename) {
         // We use getimagesize instead of extension checking, because sometimes extensions are wrong.
         list($width, $height, $type, $attr) = getimagesize($filename);
         switch ($type) {
             case 1:
                 if (function_exists('imagecreatefromgif')) {
                     $this->setGD(imagecreatefromgif($filename));
                 }
                 break;
             case 2:
                 if (function_exists('imagecreatefromjpeg')) {
                     $this->setGD(imagecreatefromjpeg($filename));
                 }
                 break;
             case 3:
                 if (function_exists('imagecreatefrompng')) {
                     $this->setGD(imagecreatefrompng($filename));
                 }
                 break;
         }
     }
     $this->quality = self::$default_quality;
     parent::__construct();
 }
 /**
  * Output file to the browser.
  * For performance reasons, we avoid SS_HTTPResponse and just output the contents instead.
  */
 public function sendFile($file)
 {
     $path = $file->getFullPath();
     if (SapphireTest::is_running_test()) {
         return file_get_contents($path);
     }
     header('Content-Description: File Transfer');
     // Quotes needed to retain spaces (http://kb.mozillazine.org/Filenames_with_spaces_are_truncated_upon_download)
     header('Content-Disposition: inline; filename="' . basename($path) . '"');
     header('Content-Length: ' . $file->getAbsoluteSize());
     header('Content-Type: ' . HTTP::get_mime_type($file->getRelativePath()));
     header('Content-Transfer-Encoding: binary');
     // Fixes IE6,7,8 file downloads over HTTPS bug (http://support.microsoft.com/kb/812935)
     header('Pragma: ');
     if ($this->config()->min_download_bandwidth) {
         // Allow the download to last long enough to allow full download with min_download_bandwidth connection.
         increase_time_limit_to((int) (filesize($path) / ($this->config()->min_download_bandwidth * 1024)));
     } else {
         // Remove the timelimit.
         increase_time_limit_to(0);
     }
     // Clear PHP buffer, otherwise the script will try to allocate memory for entire file.
     while (ob_get_level() > 0) {
         ob_end_flush();
     }
     // Prevent blocking of the session file by PHP. Without this the user can't visit another page of the same
     // website during download (see http://konrness.com/php5/how-to-prevent-blocking-php-requests/)
     session_write_close();
     readfile($path);
     die;
 }
Example #7
0
 public function __construct($filename = null)
 {
     // If we're working with image resampling, things could take a while.  Bump up the time-limit
     increase_time_limit_to(300);
     if ($filename && is_readable($filename)) {
         // We use getimagesize instead of extension checking, because sometimes extensions are wrong.
         list($width, $height, $type, $attr) = getimagesize($filename);
         switch ($type) {
             case 1:
                 if (function_exists('imagecreatefromgif')) {
                     $this->setImageResource(imagecreatefromgif($filename));
                 }
                 break;
             case 2:
                 if (function_exists('imagecreatefromjpeg')) {
                     $this->setImageResource(imagecreatefromjpeg($filename));
                 }
                 break;
             case 3:
                 if (function_exists('imagecreatefrompng')) {
                     $img = imagecreatefrompng($filename);
                     imagesavealpha($img, true);
                     // save alphablending setting (important)
                     $this->setImageResource($img);
                 }
                 break;
         }
     }
     parent::__construct();
     $this->quality = $this->config()->default_quality;
     $this->interlace = $this->config()->image_interlace;
 }
 public function run($request)
 {
     $strCSVPath = CONTINENTAL_CONTENT_PATH . '/code/ThirdParty/dbip-city.csv';
     if (!file_exists($strCSVPath)) {
         echo "<p>I cant find the dbip-city.csv file to import any data.<br>\n\t\t\t\tPlease download any database from <a href='https://db-ip.com/db/'>https://db-ip.com/db/</a>.<br>\n\t\t\t\tNOTE: It's adviced to edit the DB to only include the countries you want to handle, it contains 2 million records!!!<br>\n\t\t\t\tOr make a CSV contain these columns<br>\n\t\t\t\t`IPFrom`,`IPTo`,`Country`,`Region`,`City`\n\t\t\t\t</p>";
         //"0.0.0.0","0.255.255.255","US","California","Los Angeles"
     } else {
         if (!isset($_REQUEST['confirm'])) {
             $strLink = Director::baseURL() . 'dev/tasks/ImportDBIPcom?confirm=1';
             echo "<p>CAUTION!!!<br>\n\t\t\t\t\tPlease confirm your action<br>\n\t\t\t\t\t<a href='{$strLink}'>I confirm the action</a><br>\n\t\t\t\t\t<a href='{$strLink}&emptydb=1'>I confirm the action, please empty the DB before you import</a>\n\t\t\t\t\t</p>";
         } else {
             increase_time_limit_to();
             if (isset($_REQUEST['emptydb'])) {
                 DB::query('TRUNCATE `IpToLocation`;');
             }
             $arrFields = array_keys(Config::inst()->get('IpToLocation', 'db'));
             $handle = fopen($strCSVPath, "r");
             if ($handle) {
                 while (($line = fgets($handle)) !== false) {
                     $line = str_replace('","', '___', $line);
                     $line = str_replace('"', '', $line);
                     $arrParts = Convert::raw2sql(explode("___", $line));
                     $arrParts[0] = ContinentalContentUtils::IPAddressToIPNumber($arrParts[0]);
                     $arrParts[1] = ContinentalContentUtils::IPAddressToIPNumber($arrParts[1]);
                     DB::query('INSERT INTO `IpToLocation` (`' . implode('`,`', $arrFields) . '`) VALUES (\'' . implode('\',\'', $arrParts) . '\')');
                 }
                 fclose($handle);
             } else {
                 echo 'Error opening file';
             }
         }
     }
 }
 /**
  * Perform migration
  *
  * @param string $base Absolute base path (parent of assets folder). Will default to BASE_PATH
  * @return int Number of files successfully migrated
  */
 public function run($base = null)
 {
     if (empty($base)) {
         $base = BASE_PATH;
     }
     // Check if the File dataobject has a "Filename" field.
     // If not, cannot migrate
     if (!DB::get_schema()->hasField('File', 'Filename')) {
         return 0;
     }
     // Set max time and memory limit
     increase_time_limit_to();
     increase_memory_limit_to();
     // Loop over all files
     $count = 0;
     $filenameMap = $this->getFilenameArray();
     foreach ($this->getFileQuery() as $file) {
         // Get the name of the file to import
         $filename = $filenameMap[$file->ID];
         $success = $this->migrateFile($base, $file, $filename);
         if ($success) {
             $count++;
         }
     }
     return $count;
 }
 /**
  * Collect all changes for the given context.
  */
 public function collectChanges($context)
 {
     increase_time_limit_to();
     increase_memory_limit_to();
     if (is_callable(array($this->owner, 'objectsToUpdate'))) {
         $toUpdate = $this->owner->objectsToUpdate($context);
         if ($toUpdate) {
             foreach ($toUpdate as $object) {
                 if (!is_callable(array($this->owner, 'urlsToCache'))) {
                     continue;
                 }
                 $urls = $object->urlsToCache();
                 if (!empty($urls)) {
                     $this->toUpdate = array_merge($this->toUpdate, $this->owner->getUrlArrayObject()->addObjects($urls, $object));
                 }
             }
         }
     }
     if (is_callable(array($this->owner, 'objectsToDelete'))) {
         $toDelete = $this->owner->objectsToDelete($context);
         if ($toDelete) {
             foreach ($toDelete as $object) {
                 if (!is_callable(array($this->owner, 'urlsToCache'))) {
                     continue;
                 }
                 $urls = $object->urlsToCache();
                 if (!empty($urls)) {
                     $this->toDelete = array_merge($this->toDelete, $this->owner->getUrlArrayObject()->addObjects($urls, $object));
                 }
             }
         }
     }
 }
 /**
  * This returns the workflow requests outstanding for this user.
  * It does one query against draft for change requests, and another
  * request against live for the deletion requests (which are not in draft
  * any more), and merges the result sets together.
  */
 function sourceRecords($params)
 {
     increase_time_limit_to(120);
     $currentStage = Versioned::current_stage();
     $changes = WorkflowTwoStepRequest::get_by_author('WorkflowPublicationRequest', Member::currentUser(), array('AwaitingApproval'));
     if ($changes) {
         foreach ($changes as $change) {
             $change->RequestType = "Publish";
         }
     }
     Versioned::reading_stage(Versioned::get_live_stage());
     $deletions = WorkflowTwoStepRequest::get_by_author('WorkflowDeletionRequest', Member::currentUser(), array('AwaitingApproval'));
     if ($deletions) {
         foreach ($deletions as $deletion) {
             $deletion->RequestType = "Deletion";
         }
     }
     if ($changes && $deletions) {
         $changes->merge($deletions);
     } else {
         if ($deletions) {
             $changes = $deletions;
         }
     }
     return $changes;
 }
 public function fire()
 {
     increase_memory_limit_to();
     increase_time_limit_to();
     /** @var i18nTextCollector $collector */
     $collector = i18nTextCollector::create($this->option('locale'));
     if (!$this->option('locale')) {
         $this->info('Starting text collection. No Locale specified');
     } else {
         $this->info('Starting text collection for: ' . $this->option('locale'));
     }
     $merge = $this->getIsMerge();
     if ($merge) {
         $this->info('New strings will be merged with existing strings');
     }
     // Custom writer
     $writerName = $this->option('writer');
     if ($writerName) {
         $writer = Injector::inst()->get($writerName);
         $collector->setWriter($writer);
         $this->info('Set collector writer to: ' . $writer);
     }
     // Get restrictions
     $restrictModules = $this->option('module') ? explode(',', $this->option('module')) : null;
     $this->info('Collecting in modules: ' . $this->option('module'));
     // hack untill we have something better
     ob_start();
     $collector->run($restrictModules, $merge);
     $this->warn(ob_get_contents());
     ob_get_clean();
     $this->info(__CLASS__ . ' completed!');
 }
 function run($request)
 {
     increase_time_limit_to();
     $self = get_class($this);
     $verbose = isset($_GET['verbose']);
     if (isset($_GET['class']) && isset($_GET['id'])) {
         $item = DataObject::get($_GET['class'])->byID($_GET['id']);
         if (!$item || !$item->exists()) {
             die('not found: ' . $_GET['id']);
         }
         $item->rebuildVFI();
         echo "done";
         return;
     }
     if (isset($_GET['link'])) {
         $item = SiteTree::get_by_link($_GET['link']);
         if (!$item || !$item->exists()) {
             die('not found: ' . $_GET['link']);
         }
         $item->rebuildVFI();
         echo "done";
         return;
     }
     if (isset($_GET['start'])) {
         $this->runFrom($_GET['class'], $_GET['start'], $_GET['field']);
     } else {
         foreach (array('framework', 'sapphire') as $dirname) {
             $script = sprintf("%s%s{$dirname}%scli-script.php", BASE_PATH, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);
             if (file_exists($script)) {
                 break;
             }
         }
         $classes = VirtualFieldIndex::get_classes_with_vfi();
         foreach ($classes as $class) {
             if (isset($_GET['class']) && $class != $_GET['class']) {
                 continue;
             }
             $singleton = singleton($class);
             $query = $singleton->get($class);
             $dtaQuery = $query->dataQuery();
             $sqlQuery = $dtaQuery->getFinalisedQuery();
             $singleton->extend('augmentSQL', $sqlQuery, $dtaQuery);
             $total = $query->count();
             $startFrom = isset($_GET['startfrom']) ? $_GET['startfrom'] : 0;
             $field = isset($_GET['field']) ? $_GET['field'] : '';
             echo "Class: {$class}, total: {$total}\n\n";
             for ($offset = $startFrom; $offset < $total; $offset += $this->stat('recordsPerRequest')) {
                 echo "{$offset}..";
                 $cmd = "php {$script} dev/tasks/{$self} class={$class} start={$offset} field={$field}";
                 if ($verbose) {
                     echo "\n  Running '{$cmd}'\n";
                 }
                 $res = $verbose ? passthru($cmd) : `{$cmd}`;
                 if ($verbose) {
                     echo "  " . preg_replace('/\\r\\n|\\n/', '$0  ', $res) . "\n";
                 }
             }
         }
     }
 }
 /**
  * Note that this is duplicated for backwards compatibility purposes...
  */
 public function setup()
 {
     parent::setup();
     increase_time_limit_to();
     $restart = $this->currentStep == 0;
     if ($restart) {
         $this->pagesToProcess = DB::query('SELECT "ID" FROM SiteTree_Live WHERE ShowInSearch=1')->column();
     }
 }
 public function run($request)
 {
     $strLocationCSV = CONTINENTAL_CONTENT_PATH . '/code/ThirdParty/GeoLiteCity-Location.csv';
     $strIPCSV = CONTINENTAL_CONTENT_PATH . '/code/ThirdParty/GeoLiteCity-Blocks.csv';
     if (!file_exists($strLocationCSV) || !file_exists($strIPCSV)) {
         echo "<p>I cant find the GeoLiteCity-Location.csv or GeoLiteCity-Blocks.csv file to import any data.<br>\n\t\t\t\tPlease download the database from <a href='http://dev.maxmind.com/geoip/legacy/geolite/'>http://dev.maxmind.com/geoip/legacy/geolite/</a>.<br>\n\t\t\t\tNOTE: It's adviced to edit the DB to only include the countries you want to handle, it contains 2 million records!!!<br>\n\t\t\t\t</p>";
     } else {
         if (!isset($_REQUEST['confirm'])) {
             $strLink = Director::baseURL() . 'dev/tasks/ImportMaxMindToDatabase?confirm=1';
             echo "<p>CAUTION!!!<br>\n\t\t\t\t\tPlease confirm your action<br>\n\t\t\t\t\t<a href='{$strLink}'>I confirm the action</a><br>\n\t\t\t\t\t<a href='{$strLink}&emptydb=1'>I confirm the action, please empty the DB before you import</a>\n\t\t\t\t\t</p>";
         } else {
             $arrFields = array_keys(Config::inst()->get('IpToLocation', 'db'));
             increase_time_limit_to();
             if (isset($_REQUEST['emptydb'])) {
                 DB::query('TRUNCATE `IpToLocation`;');
             }
             $arrLocations = array();
             $handle = fopen($strLocationCSV, "r");
             if ($handle) {
                 $i = 0;
                 while (($line = fgets($handle)) !== false) {
                     $i += 1;
                     if ($i > 3) {
                         $line = str_replace('","', '**', $line);
                         $line = str_replace(',', '**', $line);
                         $line = str_replace('"', '', $line);
                         $arrParts = Convert::raw2sql(explode("**", $line));
                         $arrLocations[$arrParts[0]] = array('Country' => $arrParts[1], 'Region' => $arrParts[2], 'City' => $arrParts[3]);
                     }
                 }
                 fclose($handle);
             } else {
                 echo 'Error opening file';
             }
             $ipHandle = fopen($strIPCSV, "r");
             if ($ipHandle) {
                 $i = 0;
                 while (($line = fgets($ipHandle)) !== false) {
                     $i += 1;
                     if ($i > 3) {
                         $line = str_replace("\n", "", $line);
                         $line = str_replace('","', '___', $line);
                         $line = str_replace('"', '', $line);
                         $arrParts = Convert::raw2sql(explode("___", $line));
                         if (count($arrParts) == 3 && isset($arrLocations[$arrParts[2]])) {
                             $strSQL = 'INSERT INTO `IpToLocation` (`' . implode('`,`', $arrFields) . '`) VALUES (\'' . implode('\',\'', array_merge(array('IPFrom' => $arrParts[0], 'IPTo' => $arrParts[1]), $arrLocations[$arrParts[2]])) . '\')';
                             DB::query($strSQL);
                         }
                     }
                 }
             } else {
                 echo 'Error opening file';
             }
         }
     }
 }
 /**
  * This is the main method to build the master string tables with the original strings.
  * It will search for existent modules that use the i18n feature, parse the _t() calls
  * and write the resultant files in the lang folder of each module.
  *
  * @uses DataObject->collectI18nStatics()
  */
 public function run($request)
 {
     increase_time_limit_to();
     $c = new i18nTextCollector($request->getVar('locale'));
     $writer = $request->getVar('writer');
     if ($writer) {
         $c->setWriter(new $writer());
     }
     $restrictModules = $request->getVar('module') ? explode(',', $request->getVar('module')) : null;
     return $c->run($restrictModules, (bool) $request->getVar('merge'));
 }
Example #17
0
 public function process()
 {
     increase_time_limit_to(300);
     DB::query("DELETE FROM CachedCalendarEntry");
     $future_years = $this->config()->cache_future_years;
     foreach (Calendar::get() as $calendar) {
         echo "<h2>Caching calendar '{$calendar->Title}'</h2>\n";
         foreach ($calendar->getAllCalendars() as $c) {
             foreach ($c->AllChildren() as $event) {
                 // All the dates of regular events
                 if ($event->Recursion) {
                     echo "<h3>Creating recurring events for '{$event->Title}'</h3>\n";
                     $i = 0;
                     $dt = $event->DateTimes()->first();
                     if (!$dt) {
                         continue;
                     }
                     if ($dt->EndDate) {
                         $end_date = sfDate::getInstance($dt->EndDate);
                     } else {
                         $end_date = sfDate::getInstance()->addYear($future_years);
                     }
                     $start_date = sfDate::getInstance($dt->StartDate);
                     $recursion = $event->getRecursionReader();
                     while ($start_date->get() <= $end_date->get()) {
                         if ($recursion->recursionHappensOn($start_date->get())) {
                             $dt->StartDate = $start_date->format('Y-m-d');
                             $cached = CachedCalendarEntry::create_from_datetime($dt, $calendar);
                             $cached->EndDate = $cached->StartDate;
                             $cached->write();
                         }
                         $start_date->addDay();
                         $i++;
                     }
                     echo "<p>{$i} events created.</p>\n";
                 } else {
                     foreach ($event->DateTimes() as $dt) {
                         echo "<p>Adding dates for event '{$event->Title}'</p>\n";
                         $cached = CachedCalendarEntry::create_from_datetime($dt, $calendar);
                         $cached->write();
                     }
                 }
                 // Announcements
             }
             foreach ($c->Announcements() as $a) {
                 echo "<p>Adding announcement {$a->Title}</p>\n";
                 $cached = CachedCalendarEntry::create_from_announcement($a, $calendar);
                 $cached->write();
             }
         }
     }
     echo "Done!";
 }
 /**
  * Process the contents of the yml file specified via the first url parameter.
  */
 function load($request)
 {
     increase_time_limit_to(600);
     $requestedFiles = Convert::raw2xml(str_replace(' ', '', strtolower($request->param('ID'))));
     if (!$requestedFiles) {
         $this->message('Parameter required.');
         return;
     }
     if ($requestedFiles == 'all') {
         $requestedFiles = null;
     } else {
         $requestedFiles = explode(',', $requestedFiles);
     }
     $files = scandir(BASE_PATH . "/" . self::get_data_dir() . "/");
     foreach ($files as $file) {
         // Checking the validity of the file
         if (strpos($file, '.yml') === false || $file[0] == '.' || !is_file(BASE_PATH . "/" . self::get_data_dir() . "/" . $file)) {
             continue;
         }
         // Check if the file was requested
         $fileBase = str_replace('.yml', '', $file);
         if ($requestedFiles && !in_array(strtolower($fileBase), $requestedFiles)) {
             continue;
         }
         // Update existing objects and add new ones
         $this->message("Adding and updating objects for {$fileBase}");
         $yml = new TestDataYamlFixture(self::get_data_dir() . "/" . $file);
         $yml->saveIntoDatabase(DataModel::inst());
         $this->message("\n");
         // Remove the objects that fell behind - TestDataYamlFixture increments the tag
         // version on each run, so we can easily identify these.
         $this->message("Prunning records for {$fileBase}");
         $latestVersion = DB::query("SELECT MAX(\"Version\") FROM \"TestDataTag\" WHERE \"FixtureFile\"='{$file}'")->value();
         $tags = DataObject::get('TestDataTag', "\"FixtureFile\"='{$file}' AND \"Version\"<'{$latestVersion}'");
         if ($tags) {
             foreach ($tags as $tag) {
                 if (!class_exists($tag->Class)) {
                     $this->message("\n<span style=\"background: orange; color: black;\">WARNING: %s class does not exist, but has a TestDataTag record. Skipping...</span>\n");
                     continue;
                 }
                 $record = DataObject::get_by_id($tag->Class, $tag->RecordID, false);
                 if ($record) {
                     TestDataYamlFixture::attempt_unpublish($record);
                     $record->delete();
                 }
                 $tag->delete();
                 $this->message('.');
             }
         }
         $this->message("\n");
     }
     $this->message("<span style=\"background: green; color: white;\">SUCCESS</span>\n");
 }
 public function run($request)
 {
     HTTP::set_cache_age(0);
     increase_time_limit_to();
     // This can be a time consuming task
     $conn = DB::getConn();
     $classes = ClassInfo::subclassesFor('DataObject');
     $dbTables = $conn->tableList();
     $go = $request->getVar('go');
     if (!$go) {
         echo 'Set ?go=1 to really delete the tables';
         echo '<hr/>';
     }
     //make all lowercase
     $dbTablesLc = array_map('strtolower', $dbTables);
     $dbTablesMap = array();
     foreach ($dbTables as $k => $v) {
         $dbTablesMap[strtolower($v)] = $v;
     }
     foreach ($classes as $class) {
         if (ClassInfo::hasTable($class)) {
             $lcClass = strtolower($class);
             self::removeFromArray($lcClass, $dbTablesLc);
             //page modules
             self::removeFromArray($lcClass . '_live', $dbTablesLc);
             self::removeFromArray($lcClass . '_versions', $dbTablesLc);
             //relations
             $hasMany = Config::inst()->get($class, 'has_many');
             $manyMany = Config::inst()->get($class, 'many_many');
             if (!empty($hasMany)) {
                 foreach ($hasMany as $rel => $obj) {
                     self::removeFromArray($lcClass . '_' . strtolower($rel), $dbTablesLc);
                 }
             }
             if (!empty($manyMany)) {
                 foreach ($manyMany as $rel => $obj) {
                     self::removeFromArray($lcClass . '_' . strtolower($rel), $dbTablesLc);
                 }
             }
         }
     }
     //at this point, we should only have orphans table in dbTables var
     foreach ($dbTablesLc as $i => $lcTable) {
         $table = $dbTablesMap[$lcTable];
         if ($go) {
             DB::query('DROP TABLE `' . $table . '`');
             DB::alteration_message("Dropped {$table}", 'obsolete');
         } else {
             DB::alteration_message("Would drop {$table}", 'obsolete');
         }
     }
 }
 public function run($request)
 {
     increase_time_limit_to();
     if ($request->getVar('live')) {
         $this->live = true;
     } else {
         echo '<div>Running in <strong>test</strong> mode... to actually create link mappings, append <strong>?live=1</strong> to the URL...</div><br>';
     }
     $this->setupStructure();
     $records = $this->getPublishedVersionRecords();
     $this->processRecords($records);
     $this->checkAndCreateMappings();
     echo '<strong>Complete!</strong>';
 }
 /**
  * Updates the database schema, creating tables & fields as necessary.
  */
 public function build()
 {
     // The default time limit of 30 seconds is normally not enough
     increase_time_limit_to(600);
     // Get all our classes
     SS_ClassLoader::instance()->getManifest()->regenerate();
     if (isset($_GET['returnURL'])) {
         echo "<p>Setting up the database; you will be returned to your site shortly....</p>";
         $this->doBuild(true);
         echo "<p>Done!</p>";
         $this->redirect($_GET['returnURL']);
     } else {
         $this->doBuild(isset($_REQUEST['quiet']) || isset($_REQUEST['from_installer']), !isset($_REQUEST['dont_populate']));
     }
 }
Example #22
0
 /**
  * Updates the database schema, creating tables & fields as necessary.
  */
 function build()
 {
     // The default time limit of 30 seconds is normally not enough
     increase_time_limit_to(600);
     // Get all our classes
     ManifestBuilder::create_manifest_file();
     require MANIFEST_FILE;
     if (isset($_GET['returnURL'])) {
         echo "<p>Setting up the database; you will be returned to your site shortly....</p>";
         $this->doBuild(true);
         echo "<p>Done!</p>";
         Director::redirect($_GET['returnURL']);
     } else {
         $this->doBuild(isset($_REQUEST['quiet']) || isset($_REQUEST['from_installer']), !isset($_REQUEST['dont_populate']));
     }
 }
 /**
  * Note that this is duplicated for backwards compatibility purposes...
  */
 public function setup()
 {
     parent::setup();
     increase_time_limit_to();
     $restart = $this->currentStep == 0;
     if (!$this->tempFile || !file_exists($this->tempFile)) {
         $tmpfile = tempnam(getTempFolder(), 'sitemap');
         if (file_exists($tmpfile)) {
             $this->tempFile = $tmpfile;
         }
         $restart = true;
     }
     if ($restart) {
         $this->pagesToProcess = DB::query('SELECT ID FROM SiteTree_Live WHERE ShowInSearch=1')->column();
     }
 }
 /**
  * This is the main method to build the master string tables with the original strings.
  * It will search for existent modules that use the i18n feature, parse the _t() calls
  * and write the resultant files in the lang folder of each module.
  *
  * @uses DataObject->collectI18nStatics()
  *
  * @param SS_HTTPRequest $request
  */
 public function run($request)
 {
     increase_time_limit_to();
     $collector = i18nTextCollector::create($request->getVar('locale'));
     $merge = $this->getIsMerge($request);
     // Custom writer
     $writerName = $request->getVar('writer');
     if ($writerName) {
         $writer = Injector::inst()->get($writerName);
         $collector->setWriter($writer);
     }
     // Get restrictions
     $restrictModules = $request->getVar('module') ? explode(',', $request->getVar('module')) : null;
     $collector->run($restrictModules, $merge);
     Debug::message(__CLASS__ . " completed!", false);
 }
 /**
  * Note that this is duplicated for backwards compatibility purposes...
  */
 public function setup()
 {
     parent::setup();
     increase_time_limit_to();
     $restart = $this->currentStep == 0;
     if (!$this->tempFile || !file_exists($this->tempFile)) {
         $tmpfile = tempnam(getTempFolder(), 'postsitemap');
         if (file_exists($tmpfile)) {
             $this->tempFile = $tmpfile;
         }
         $restart = true;
     }
     if ($restart) {
         $this->toProcess = $this->getProcessIds();
     }
 }
Example #26
0
 function testIncreaseTimeLimitTo()
 {
     set_time_limit(6000);
     // It can go up
     increase_time_limit_to(7000);
     $this->assertEquals(7000, ini_get('max_execution_time'));
     // But not down
     increase_time_limit_to(5000);
     $this->assertEquals(7000, ini_get('max_execution_time'));
     // 0/nothing means infinity
     increase_time_limit_to();
     $this->assertEquals(0, ini_get('max_execution_time'));
     // Can't go down from there
     increase_time_limit_to(10000);
     $this->assertEquals(0, ini_get('max_execution_time'));
 }
 public function run($request)
 {
     $strCSVPath = CONTINENTAL_CONTENT_PATH . '/code/ThirdParty/dbip-city.csv';
     if (!file_exists($strCSVPath)) {
         echo "<p>I cant find the dbip-city.csv file to import any data.<br>\n\t\t\t\tPlease download any database from <a href='https://db-ip.com/db/'>https://db-ip.com/db/</a>.<br>\n\t\t\t\tNOTE: It's adviced to edit the DB to only include the countries you want to handle, it contains 2 million records!!!<br>\n\t\t\t\tOr make a CSV contain these columns<br>\n\t\t\t\t`IPFrom`,`IPTo`,`Country`,`Region`,`City`\n\t\t\t\t</p>";
         //"0.0.0.0","0.255.255.255","US","California","Los Angeles"
     } else {
         if (!isset($_REQUEST['confirm'])) {
             $strLink = Director::baseURL() . 'dev/tasks/ImportDBIPcom?confirm=1';
             echo "<p>CAUTION!!!<br>\n\t\t\t\t\tPlease confirm your action<br>\n\t\t\t\t\t<a href='{$strLink}'>I confirm the action</a><br>\n\t\t\t\t\t<a href='{$strLink}&emptydb=1'>I confirm the action, please empty the DB before you import</a>\n\t\t\t\t\t</p>";
         } else {
             increase_time_limit_to();
             //
             // this needs varbinary fields so create the table here
             //
             $arr = DB::table_list();
             if (!in_array('dbip_lookup', $arr)) {
                 $strSQL = "CREATE TABLE `dbip_lookup` (\n\t\t\t\t\t  `addr_type` enum('ipv4','ipv6') NOT NULL,\n\t\t\t\t\t  `ip_start` varbinary(16) NOT NULL,\n\t\t\t\t\t  `ip_end` varbinary(16) NOT NULL,\n\t\t\t\t\t  `country` char(2) NOT NULL,\n\t\t\t\t\t  `stateprov` varchar(80) NOT NULL,\n\t\t\t\t\t  `city` varchar(80) NOT NULL,\n\t\t\t\t\t  PRIMARY KEY (`ip_start`)\n\t\t\t\t\t);";
                 DB::query($strSQL);
             }
             if (isset($_REQUEST['emptydb'])) {
                 DB::query('TRUNCATE `dbip_lookup`;');
             }
             $conn = DB::get_conn();
             if ($conn->supportsTransactions()) {
                 $conn->transactionStart();
             }
             $handle = fopen($strCSVPath, "r");
             if ($handle) {
                 while (($line = fgets($handle)) !== false) {
                     $line = str_replace('","', '___', $line);
                     $line = str_replace('"', '', $line);
                     $arrParts = Convert::raw2sql(explode("___", $line));
                     $vals = array('addr_type' => "'" . IpToLocation::addr_type($arrParts[0]) . "'", 'ip_start' => "'" . $conn->escapeString(ContinentalContentUtils::IPAddressToIPNumber($arrParts[0])) . "'", 'ip_end' => "'" . $conn->escapeString(ContinentalContentUtils::IPAddressToIPNumber($arrParts[1])) . "'", 'country' => "'" . $arrParts[2] . "'", 'stateprov' => "'" . $arrParts[3] . "'", 'city' => "'" . $arrParts[4] . "'");
                     $fields = array_keys($vals);
                     DB::query('INSERT INTO `dbip_lookup` (`' . implode('`,`', $fields) . '`) VALUES (' . implode(',', $vals) . ')');
                 }
                 fclose($handle);
             } else {
                 echo 'Error opening file';
             }
             if ($conn->supportsTransactions()) {
                 $conn->transactionEnd();
             }
         }
     }
 }
 public function process()
 {
     increase_time_limit_to();
     echo "SENDING QUEUED EMAILS\n";
     $queued = DataObject::get('QueuedEmail', "\"Send\" < " . DB::getConn()->now());
     if (!$queued) {
         return;
     }
     foreach ($queued as $data) {
         if (!$data->canSendEmail()) {
             continue;
         }
         $data->send();
         echo 'Sent to: ' . $data->To()->Email . "\n";
         $data->delete();
     }
 }
Example #29
0
 /**
  * Updates the database schema, creating tables & fields as necessary.
  */
 function build()
 {
     // The default time limit of 30 seconds is normally not enough
     increase_time_limit_to(600);
     // Get all our classes
     SS_ClassLoader::instance()->getManifest()->regenerate();
     if (isset($_GET['returnURL'])) {
         echo "<p>Setting up the database; you will be returned to your site shortly....</p>";
         $this->doBuild(true);
         echo "<p>Done!</p>";
         Director::redirect($_GET['returnURL']);
     } else {
         if (!Director::is_cli() && Director::urlParam('Controller') == __CLASS__) {
             echo '<p style="color: red;"><i>db/build</i> has been deprecated. Please use <b>dev/build</b> instead.</p>';
         }
         $this->doBuild(isset($_REQUEST['quiet']) || isset($_REQUEST['from_installer']), !isset($_REQUEST['dont_populate']));
     }
 }
 public function minify($content, $type, $filename)
 {
     // Non-js files aren't minified
     if ($type !== 'js') {
         return $content . "\n";
     }
     // Combine JS
     try {
         require_once 'thirdparty/jsmin/jsmin.php';
         increase_time_limit_to();
         $content = JSMin::minify($content);
     } catch (Exception $e) {
         $message = $e->getMessage();
         user_error("Failed to minify {$filename}, exception: {$message}", E_USER_WARNING);
     } finally {
         return $content . ";\n";
     }
 }