Exemplo n.º 1
0
 protected function afterSubmit(&$response, &$model, &$params, $modifiedAttributes)
 {
     $stmt = \GO\Addressbook\Model\Addresslist::model()->find(\GO\Base\Db\FindParams::newInstance()->permissionLevel(\GO\Base\Model\Acl::WRITE_PERMISSION));
     while ($addresslist = $stmt->fetch()) {
         $linkModel = $addresslist->hasManyMany('contacts', $model->id);
         $mustHaveLinkModel = isset($params['addresslist_' . $addresslist->id]);
         if ($linkModel && !$mustHaveLinkModel) {
             $linkModel->delete();
         }
         if (!$linkModel && $mustHaveLinkModel) {
             $addresslist->addManyMany('contacts', $model->id);
         }
     }
     if (!empty($params['delete_photo'])) {
         $model->removePhoto();
         $model->save();
     }
     if (isset($_FILES['image']['tmp_name'][0]) && is_uploaded_file($_FILES['image']['tmp_name'][0])) {
         $destinationFile = new \GO\Base\Fs\File(\GO::config()->getTempFolder()->path() . '/' . $_FILES['image']['name'][0]);
         move_uploaded_file($_FILES['image']['tmp_name'][0], $destinationFile->path());
         $model->setPhoto($destinationFile);
         $model->save();
         $response['photo_url'] = $model->photoThumbURL;
         $response['original_photo_url'] = $model->photoURL;
     } elseif (!empty($params['download_photo_url'])) {
         $file = \GO\Base\Fs\File::tempFile();
         $c = new \GO\Base\Util\HttpClient();
         if (!$c->downloadFile($params['download_photo_url'], $file)) {
             throw new \Exception("Could not download photo from: '" . $params['download_photo_url'] . "'");
         }
         $model->setPhoto($file);
         $model->save();
         $response['photo_url'] = $model->photoThumbURL;
         $response['original_photo_url'] = $model->photoURL;
     }
     return parent::afterSubmit($response, $model, $params, $modifiedAttributes);
 }
Exemplo n.º 2
0
 protected function actionDownloadFromShop($params)
 {
     $this->requireCli();
     $proPackageName = 'groupoffice-pro';
     $this->checkRequiredParameters(array('shopuser', 'shoppass'), $params);
     $shopUrl = 'https://intermesh.group-office.com/';
     $packages = isset($params['packages']) ? explode(",", $params['packages']) : array('documents-4.0', 'billing-4.0', 'groupoffice-pro-4.0');
     $downloads = array();
     foreach ($packages as $package_name) {
         echo "\nGetting latest " . $package_name . "\n";
         $packageUrl = $shopUrl . '?r=licenses/package/downloadPackageFile&package_name=' . $package_name;
         $c = new \GO\Base\Util\HttpClient();
         if (!$c->groupofficeLogin($shopUrl, $params['shopuser'], $params['shoppass'])) {
             exit("Bad user name or password for shop");
         } else {
             echo "Shop login successful\n";
         }
         $tmpDir = new \GO\Base\Fs\Folder(getcwd());
         if (!$tmpDir->isWritable()) {
             exit("Error: " . $tmpDir->path() . " is not writable!\n");
         }
         $file = $tmpDir->createChild($package_name . '.tar.gz');
         echo "Downloading file from shop...\n";
         if (!$c->downloadFile($packageUrl, $file)) {
             exit("Error: Failed to download file");
         }
         $file->rename($c->getLastDownloadedFilename());
         $downloads[] = $file;
         if (!empty($params['replacefolder'])) {
             $params['unpack'] = 1;
         }
         //echo "Filename: ".$c->getLastDownloadedFilename()."\n";
         echo "File saved in " . $file->path() . "\n";
         if (!empty($params['unpack'])) {
             echo "Unpacking " . $file->name() . "\n";
             system('tar zxf ' . $file->name());
         }
     }
     if (!empty($params['unpack'])) {
         foreach ($downloads as $download) {
             if (strpos($download->name(), $proPackageName) !== false) {
                 $proDownload = $download;
                 break;
             }
         }
         if (empty($proDownload)) {
             exit("Error: Can't unpack. Group-Office Professional was not part of the downloads\n");
         }
         echo "Moving modules into pro package\n";
         $downloadFolder = str_replace('.tar.gz', '', $proDownload->name());
         $newFolder = new \GO\Base\Fs\Folder(getcwd() . '/' . $downloadFolder);
         if (!$newFolder->exists()) {
             exit("Download folder " . $newFolder->path() . " does not exist.\n");
         }
         foreach ($downloads as $download) {
             if (strpos($download->name(), $proPackageName) === false) {
                 $modPackageName = str_replace('.tar.gz', '', $download->name());
                 system('rm -Rf ' . $modPackageName . '/professional');
                 system('mv ' . $modPackageName . '/* ' . $downloadFolder . '/modules/');
                 system('rm -Rf ' . $modPackageName . '*');
                 $proDownload->delete();
             }
         }
         if (!empty($params['replacefolder'])) {
             $params['replacefolder'] = realpath($params['replacefolder']);
             echo "Replacing: " . $params['replacefolder'] . "\n";
             $replaceFolder = new \GO\Base\Fs\Folder($params['replacefolder']);
             $origFolderName = $replaceFolder->name();
             $backupName = $origFolderName . '_bak_' . date('YmdGis');
             echo "Creating backup in " . $backupName . "\n";
             if (!$replaceFolder->exists()) {
                 exit("Error: Folder " . $params['replacefolder'] . " does not exist!\n");
             }
             if (!$replaceFolder->rename($backupName)) {
                 die("Failed to rename " . $replaceFolder->path() . "\n");
             }
             //				$newFolder = new \GO\Base\Fs\Folder(getcwd().'/'.$downloadFolder);
             if (!$newFolder->rename($origFolderName)) {
                 die("Failed to rename " . $newFolder->path() . "\n");
             }
             //there might be a config file or license file in the directory
             echo "Copying possible config and license files\n";
             system('cp ' . $replaceFolder->path() . '/config.php ' . $replaceFolder->path() . '/*license.txt ' . $newFolder->path() . '/');
         }
     }
     echo "All done\n";
 }
Exemplo n.º 3
0
 private static function _savePhoto(&$response, &$model, &$params)
 {
     if (!empty($params['delete_photo'])) {
         $model->removePhoto();
         $model->save();
     }
     if (isset($_FILES['image']['tmp_name'][0]) && is_uploaded_file($_FILES['image']['tmp_name'][0])) {
         $destinationFile = new \GO\Base\Fs\File(\GO::config()->getTempFolder()->path() . '/' . $_FILES['image']['name'][0]);
         move_uploaded_file($_FILES['image']['tmp_name'][0], $destinationFile->path());
         $model->setPhoto($destinationFile);
         $model->save();
         $response['photo_url'] = $model->photoThumbURL;
         $response['original_photo_url'] = $model->photoURL;
     } elseif (!empty($params['download_photo_url'])) {
         $file = \GO\Base\Fs\File::tempFile();
         $c = new \GO\Base\Util\HttpClient();
         if (!$c->downloadFile($params['download_photo_url'], $file)) {
             throw new \Exception("Could not download photo from: '" . $params['download_photo_url'] . "'");
         }
         $model->setPhoto($file);
         $model->save();
         $response['photo_url'] = $model->photoThumbURL;
         $response['original_photo_url'] = $model->photoURL;
     }
 }