コード例 #1
0
ファイル: Standard.php プロジェクト: mvnp/aimeos-core
 /**
  * Uploads a XLS file with all attribute texts.
  *
  * @param \stdClass $params Object containing the properties
  */
 public function uploadFile(\stdClass $params)
 {
     $this->checkParams($params, array('site'));
     $this->setLocale($params->site);
     if (($fileinfo = reset($_FILES)) === false) {
         throw new \Aimeos\Controller\ExtJS\Exception('No file was uploaded');
     }
     $config = $this->getContext()->getConfig();
     /** controller/extjs/attribute/import/text/standard/enablecheck
      * Enables checking uploaded files if they are valid and not part of an attack
      *
      * This configuration option is for unit testing only! Please don't disable
      * the checks for uploaded files in production environments as this
      * would give attackers the possibility to infiltrate your installation!
      *
      * @param boolean True to enable, false to disable
      * @since 2014.03
      * @category Developer
      */
     if ($config->get('controller/extjs/attribute/import/text/standard/enablecheck', true)) {
         $this->checkFileUpload($fileinfo['tmp_name'], $fileinfo['error']);
     }
     $fileext = pathinfo($fileinfo['name'], PATHINFO_EXTENSION);
     $dest = md5($fileinfo['name'] . time() . getmypid()) . '.' . $fileext;
     $fs = $this->getContext()->getFilesystemManager()->get('fs-admin');
     $fs->writef($dest, $fileinfo['tmp_name']);
     $result = (object) array('site' => $params->site, 'items' => array((object) array('job.label' => 'Attribute text import: ' . $fileinfo['name'], 'job.method' => 'Attribute_Import_Text.importFile', 'job.parameter' => array('site' => $params->site, 'items' => $dest), 'job.status' => 1)));
     $jobController = \Aimeos\Controller\ExtJS\Admin\Job\Factory::createController($this->getContext());
     $jobController->saveItems($result);
     return array('items' => $dest, 'success' => true);
 }
コード例 #2
0
ファイル: BaseTest.php プロジェクト: mvnp/aimeos-core
 public function testInjectControllerReset()
 {
     $controller = \Aimeos\Controller\ExtJS\Admin\Job\Factory::createController($this->context, 'Standard');
     \Aimeos\Controller\ExtJS\Admin\Job\Factory::injectController('\\Aimeos\\Controller\\ExtJS\\Admin\\Job\\Standard', $controller);
     \Aimeos\Controller\ExtJS\Admin\Job\Factory::injectController('\\Aimeos\\Controller\\ExtJS\\Admin\\Job\\Standard', null);
     $new = \Aimeos\Controller\ExtJS\Admin\Job\Factory::createController($this->context, 'Standard');
     $this->assertNotSame($controller, $new);
 }
コード例 #3
0
ファイル: Standard.php プロジェクト: mvnp/aimeos-core
 /**
  * Creates a new job to export a file.
  *
  * @param \stdClass $params Object containing the properties, e.g. the list of catalog IDs
  */
 public function createJob(\stdClass $params)
 {
     $this->checkParams($params, array('site', 'items'));
     $this->setLocale($params->site);
     $context = $this->getContext();
     $items = (array) $params->items;
     $lang = property_exists($params, 'lang') ? (array) $params->lang : array();
     $languages = !empty($lang) ? implode($lang, '-') : 'all';
     $result = (object) array('site' => $params->site, 'items' => array((object) array('job.label' => 'Catalog text export: ' . $languages, 'job.method' => 'Catalog_Export_Text.exportFile', 'job.parameter' => array('site' => $params->site, 'items' => $items, 'lang' => $params->lang), 'job.status' => 1)));
     $jobController = \Aimeos\Controller\ExtJS\Admin\Job\Factory::createController($context);
     $jobController->saveItems($result);
     return array('items' => $items, 'success' => true);
 }
コード例 #4
0
ファイル: StandardTest.php プロジェクト: mvnp/aimeos-core
 public function testUploadFile()
 {
     $jobController = \Aimeos\Controller\ExtJS\Admin\Job\Factory::createController($this->context);
     $testfiledir = __DIR__ . DIRECTORY_SEPARATOR . 'testfiles' . DIRECTORY_SEPARATOR;
     exec(sprintf('cp -r %1$s %2$s', escapeshellarg($testfiledir) . '*', escapeshellarg($this->testdir)));
     $_FILES['unittest'] = array('name' => 'file.txt', 'tmp_name' => $this->testdir . DIRECTORY_SEPARATOR . 'file.txt', 'error' => UPLOAD_ERR_OK);
     $params = new \stdClass();
     $params->items = 'file.txt';
     $params->site = $this->context->getLocale()->getSite()->getCode();
     $result = $this->object->uploadFile($params);
     $this->assertTrue(file_exists($this->testdir . DIRECTORY_SEPARATOR . $result['items']));
     unlink($result['items']);
     $params = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => (object) array('~=' => (object) array('job.label' => 'file.txt')))));
     $result = $jobController->searchItems($params);
     $this->assertEquals(1, count($result['items']));
     $deleteParams = (object) array('site' => 'unittest', 'items' => $result['items'][0]->{'job.id'});
     $jobController->deleteItems($deleteParams);
     $result = $jobController->searchItems($params);
     $this->assertEquals(0, count($result['items']));
 }
コード例 #5
0
ファイル: Standard.php プロジェクト: boettner-it/aimeos-core
 /**
  * Uploads a file with coupon codes and meta information.
  *
  * @param \stdClass $params Object containing the properties
  */
 public function uploadFile(\stdClass $params)
 {
     $this->checkParams($params, array('site', 'couponid'));
     $this->setLocale($params->site);
     if (($fileinfo = reset($_FILES)) === false) {
         throw new \Aimeos\Controller\ExtJS\Exception('No file was uploaded');
     }
     $config = $this->getContext()->getConfig();
     /** controller/extjs/coupon/code/standard/uploaddir
      * Upload directory for text files that should be imported
      *
      * The upload directory must be an absolute path. Avoid a trailing slash
      * at the end of the upload directory string!
      *
      * @param string Absolute path including a leading slash
      * @since 2014.09
      * @category Developer
      */
     $dir = $config->get('controller/extjs/coupon/code/standard/uploaddir', 'uploads');
     /** controller/extjs/coupon/code/standard/enablecheck
      * Enables checking uploaded files if they are valid and not part of an attack
      *
      * This configuration option is for unit testing only! Please don't disable
      * the checks for uploaded files in production environments as this
      * would give attackers the possibility to infiltrate your installation!
      *
      * @param boolean True to enable, false to disable
      * @since 2014.09
      * @category Developer
      */
     if ($config->get('controller/extjs/coupon/code/standard/enablecheck', true)) {
         $this->checkFileUpload($fileinfo['tmp_name'], $fileinfo['error']);
     }
     $fileext = pathinfo($fileinfo['name'], PATHINFO_EXTENSION);
     $dest = $dir . DIRECTORY_SEPARATOR . md5($fileinfo['name'] . time() . getmypid()) . '.' . $fileext;
     if (rename($fileinfo['tmp_name'], $dest) !== true) {
         $msg = sprintf('Uploaded file could not be moved to upload directory "%1$s"', $dir);
         throw new \Aimeos\Controller\ExtJS\Exception($msg);
     }
     /** controller/extjs/coupon/code/standard/fileperms
      * File permissions used when storing uploaded files
      *
      * The representation of the permissions is in octal notation (using 0-7)
      * with a leading zero. The first number after the leading zero are the
      * permissions for the web server creating the directory, the second is
      * for the primary group of the web server and the last number represents
      * the permissions for everyone else.
      *
      * You should use 0660 or 0600 for the permissions as the web server needs
      * to manage the files. The group permissions are important if you plan
      * to upload files directly via FTP or by other means because then the
      * web server needs to be able to read and manage those files. In this
      * case use 0660 as permissions, otherwise you can limit them to 0600.
      *
      * A more detailed description of the meaning of the Unix file permission
      * bits can be found in the Wikipedia article about
      * {@link https://en.wikipedia.org/wiki/File_system_permissions#Numeric_notation file system permissions}
      *
      * @param integer Octal Unix permission representation
      * @since 2014.09
      * @category Developer
      */
     $perms = $config->get('controller/extjs/coupon/code/standard/fileperms', 0660);
     if (chmod($dest, $perms) !== true) {
         $msg = sprintf('Could not set permissions "%1$s" for file "%2$s"', $perms, $dest);
         throw new \Aimeos\Controller\ExtJS\Exception($msg);
     }
     $result = (object) array('site' => $params->site, 'items' => array((object) array('job.label' => 'Coupon code import: ' . $fileinfo['name'], 'job.method' => 'Coupon_Code.importFile', 'job.parameter' => array('site' => $params->site, 'couponid' => $params->couponid, 'items' => $dest), 'job.status' => 1)));
     $jobController = \Aimeos\Controller\ExtJS\Admin\Job\Factory::createController($this->getContext());
     $jobController->saveItems($result);
     return array('items' => $dest, 'success' => true);
 }
コード例 #6
0
 public function testUploadFile()
 {
     $helper = $this->getMockBuilder('\\Aimeos\\MW\\View\\Helper\\Request\\Standard')->setMethods(array('getUploadedFiles'))->disableOriginalConstructor()->getMock();
     $view = new \Aimeos\MW\View\Standard();
     $view->addHelper('request', $helper);
     $this->context->setView($view);
     $object = $this->getMockBuilder('\\Aimeos\\Controller\\ExtJS\\Product\\Import\\Text\\Standard')->setConstructorArgs(array($this->context))->setMethods(array('storeFile'))->getMock();
     $object->expects($this->once())->method('storeFile')->will($this->returnValue('file.txt'));
     $params = new \stdClass();
     $params->items = 'file.txt';
     $params->site = $this->context->getLocale()->getSite()->getCode();
     $object->uploadFile($params);
     $jobController = \Aimeos\Controller\ExtJS\Admin\Job\Factory::createController($this->context);
     $params = (object) array('site' => 'unittest', 'condition' => (object) array('&&' => array(0 => (object) array('~=' => (object) array('job.parameter' => 'file.txt')))));
     $result = $jobController->searchItems($params);
     $this->assertEquals(1, count($result['items']));
     $deleteParams = (object) array('site' => 'unittest', 'items' => $result['items'][0]->{'job.id'});
     $jobController->deleteItems($deleteParams);
     $result = $jobController->searchItems($params);
     $this->assertEquals(0, count($result['items']));
 }
コード例 #7
0
 public function testFactoryExceptionWrongInterface()
 {
     $this->setExpectedException('\\Aimeos\\Controller\\ExtJS\\Exception');
     \Aimeos\Controller\ExtJS\Admin\Job\Factory::createController(\TestHelper::getContext(), 'Factory');
 }
コード例 #8
0
ファイル: ExampleTest.php プロジェクト: mvnp/aimeos-core
 protected function setUp()
 {
     $context = \TestHelperExtjs::getContext();
     $controller = \Aimeos\Controller\ExtJS\Admin\Job\Factory::createController($context);
     $this->object = new \Aimeos\Controller\ExtJS\Common\Decorator\Example($controller, $context);
 }