Example #1
0
 public function test_should_generate_controller_and_auxiliary_files()
 {
     $files = array(AkConfig::getDir('controllers') . DS . 'credit_card_controller.php', AkConfig::getDir('helpers') . DS . 'credit_card_helper.php', AkConfig::getDir('test') . DS . 'functional' . DS . 'controllers' . DS . 'credit_card_controller_test.php', AkConfig::getDir('test') . DS . 'unit' . DS . 'helpers' . DS . 'credit_card_helper_test.php', AkConfig::getDir('views') . DS . 'credit_card' . DS . 'open.html.tpl', AkConfig::getDir('views') . DS . 'credit_card' . DS . 'debit.html.tpl', AkConfig::getDir('views') . DS . 'credit_card' . DS . 'credit.html.tpl', AkConfig::getDir('views') . DS . 'credit_card' . DS . 'close.html.tpl');
     clearstatcache();
     foreach ($files as $file) {
         file_exists($file) && unlink($file);
         $this->assertFalse(file_exists($file));
     }
     AkFileSystem::file_put_contents(AkConfig::getDir('views') . DS . 'credit_card' . DS . 'credit.html.tpl', 'foo', array('base_path' => AK_FRAMEWORK_DIR));
     clearstatcache();
     $this->assertPattern('/collisions/', $this->runGeneratorCommand('controller CreditCard open debit credit close'));
     AkFileSystem::file_delete(AkConfig::getDir('views') . DS . 'credit_card' . DS . 'credit.html.tpl', array('base_path' => AK_FRAMEWORK_DIR));
     clearstatcache();
     foreach ($files as $file) {
         $this->assertFalse(file_exists($file));
     }
     $this->assertPattern('/ files have been created/', $this->runGeneratorCommand('controller CreditCard open debit credit close'));
     clearstatcache();
     foreach ($files as $file) {
         $this->assertTrue(file_exists($file));
         if (!file_exists($file)) {
             AkDebug::trace($file);
         }
         @unlink($file);
     }
 }
Example #2
0
 public function Test_file_delete()
 {
     $this->assertFalse(!AkFileSystem::file_delete(AkConfig::getDir('tmp') . DS . 'test_file_1.txt'));
     $this->assertFalse(!AkFileSystem::file_delete(AkConfig::getDir('tmp') . DS . 'test_file_2.txt'));
     $this->assertFalse(!AkFileSystem::file_delete('cache/test_file_3.txt'));
     $this->assertFalse(!AkFileSystem::file_delete('cache/test_file_4.txt'));
     $this->assertFalse(!AkFileSystem::file_delete('ak_test_folder/new_folder/test_file.txt'));
 }
Example #3
0
 public function tearDown()
 {
     AkFileSystem::file_delete($this->_base_config_path . DS . 'testing' . DS . 'testconfig1.php', array('base_path' => $this->_base_config_path));
     AkFileSystem::file_delete($this->_base_config_path . DS . 'development' . DS . 'testconfig1.php', array('base_path' => $this->_base_config_path));
     AkFileSystem::file_delete($this->_base_config_path . DS . 'production' . DS . 'testconfig1.php', array('base_path' => $this->_base_config_path));
     AkFileSystem::rmdir_tree($this->_base_config_path . DS . 'testing');
     AkFileSystem::rmdir_tree($this->_base_config_path . DS . 'development');
     AkFileSystem::rmdir_tree($this->_base_config_path . DS . 'production');
     AkFileSystem::file_delete(AkConfig::getDir('config') . DS . 'testconfig1.yml', array('base_path' => $this->_base_config_path));
     AkFileSystem::rmdir_tree($this->_base_config_path);
     AkFileSystem::rmdir_tree(AkConfig::getDir('tmp') . DS . 'ak_config');
 }
Example #4
0
 public function convert()
 {
     $excel = new COM('excel.application') or die('Unable to instantiate Excel');
     $excel->Visible = false;
     $excel->WorkBooks->Open($this->source_file);
     $excel->WorkBooks[1]->SaveAs($this->destination_file, $this->_file_type_codes[$this->convert_to]);
     $excel->Quit();
     unset($excel);
     $result = AkFileSystem::file_get_contents($this->destination_file);
     $this->delete_source_file ? @AkFileSystem::file_delete($this->source_file) : null;
     $this->keep_destination_file ? null : AkFileSystem::file_delete($this->destination_file);
     return $result;
 }
Example #5
0
 public function convert()
 {
     $word = new COM('word.application') or die('Unable to instantiate Word');
     $word->Visible = false;
     $word->Documents->Open($this->source_file);
     $word->Documents[1]->SaveAs($this->destination_file, $this->_file_type_codes[$this->convert_to]);
     $word->Quit();
     $word = null;
     $result = AkFileSystem::file_get_contents($this->destination_file);
     $this->delete_source_file ? AkFileSystem::file_delete($this->source_file) : null;
     $this->keep_destination_file ? null : AkFileSystem::file_delete($this->destination_file);
     return $result;
 }
Example #6
0
 public function convert()
 {
     $xdoc2txt_bin = AK_CONTRIB_DIR . DS . 'hyperestraier' . DS . 'xdoc2txt.exe';
     if (!AK_WIN) {
         trigger_error(Ak::t('Xdoc2Text is a windows only application. Please use wvWare instead'), E_USER_WARNING);
         return false;
     }
     if (!file_exists($xdoc2txt_bin)) {
         trigger_error(Ak::t('Could not find xdoc2txt.exe on %path. Please download it from http://www31.ocn.ne.jp/~h_ishida/xdoc2txt.html', array('%path' => $xdoc2txt_bin)), E_USER_WARNING);
         return false;
     }
     exec('@"' . $xdoc2txt_bin . '" -f "' . $this->source_file . '" "' . $this->destination_file . '"');
     $result = AkFileSystem::file_get_contents($this->destination_file);
     $this->delete_source_file ? @AkFileSystem::file_delete($this->source_file) : null;
     $this->keep_destination_file ? null : AkFileSystem::file_delete($this->destination_file);
     return $result;
 }
Example #7
0
 public function convert()
 {
     $this->handler->read($this->source_file);
     $result = array();
     for ($i = 1; $i <= $this->handler->sheets[0]['numRows']; $i++) {
         if ($i === 1) {
             @($col_names = $this->handler->sheets[0]['cells'][$i - 1]);
             foreach (range(1, $this->handler->sheets[0]['numCols']) as $column_number) {
                 $col_names[$column_number - 1] = empty($col_names[$column_number - 1]) ? $column_number : trim($col_names[$column_number - 1], "\t\n\r ");
             }
             continue;
         }
         for ($j = 0; $j < $this->handler->sheets[0]['numCols']; $j++) {
             $result[$i - 2][$col_names[$j]] = isset($this->handler->sheets[0]['cells'][$i - 1][$j]) ? $this->handler->sheets[0]['cells'][$i - 1][$j] : null;
         }
     }
     $this->delete_source_file ? @AkFileSystem::file_delete($this->source_file) : null;
     return $result;
 }
Example #8
0
 private function _setExternals($items, $extras = '')
 {
     $externals = array();
     foreach ($items as $name => $uri) {
         $externals[] = "{$name} " . rtrim($uri, '/');
     }
     $tmp_file = AK_TMP_DIR . DS . Ak::uuid();
     $plugins_dir = AK_PLUGINS_DIR;
     AkFileSystem::file_put_contents($tmp_file, join("\n", $externals));
     `svn propset {$extras} -q svn:externals -F "{$tmp_file}" "{$plugins_dir}"`;
     AkFileSystem::file_delete($tmp_file);
 }
Example #9
0
 public function test_cleanup()
 {
     @AkFileSystem::file_delete(AkConfig::getDir('models') . DS . 'group_user.php', array('base_path' => AkConfig::getDir('models')));
 }
Example #10
0
 public function uninstall($version = null, $options = array())
 {
     $this->dropTable('properties', array('sequence' => true));
     $this->dropTable('properties_property_types', array('sequence' => true));
     @AkFileSystem::file_delete(AK_MODELS_DIR . DS . 'property_property_type.php');
 }
Example #11
0
 public function _cleanUpAutomaticGeneratedFiles()
 {
     foreach (explode(',', 'post_tag,post_user,friend_friend,aa_ee,bb_cc,dd_ee,group_user') as $file) {
         @AkFileSystem::file_delete(AkConfig::getDir('models') . DS . $file . '.php');
     }
 }
Example #12
0
 public function test_clear()
 {
     AkFileSystem::file_delete(AkConfig::getDir('models') . DS . 'todo_service.php');
 }
Example #13
0
 public function runTaskAsDaemon($task_name, $options = array())
 {
     $this->_ensurePosixAndPcntlAreAvailable();
     require_once 'System/Daemon.php';
     $app_name = AkInflector::underscore($task_name);
     $pid_file = AK_BASE_DIR . DS . 'run' . DS . $app_name . DS . $app_name . '.pid';
     $log_file = AK_LOG_DIR . DS . 'daemons' . DS . $app_name . '.log';
     if (!file_exists($pid_file)) {
         if (empty($options['attributes']['kill'])) {
             AkFileSystem::file_put_contents($pid_file, '');
             AkFileSystem::file_delete($pid_file);
         } else {
             $this->error("Could not kill process for {$task_name}", true);
         }
     } else {
         $pid = (int) file_get_contents($pid_file);
         if ($pid > 0) {
             if (!empty($options['attributes']['kill'])) {
                 $this->message("Killing process {$pid}");
                 `kill {$pid}`;
                 AkFileSystem::file_delete($pid_file);
                 die;
             } elseif (!empty($options['attributes']['restart'])) {
                 $this->message("Restarting {$task_name}.");
                 $this->message(`kill {$pid}`);
             } else {
                 $this->error("Daemon for {$task_name} still running ({$pid_file}).\nTask aborted.", true);
             }
         }
     }
     if (!empty($options['attributes']['kill']) && empty($pid)) {
         $this->error("No daemon running for task {$task_name}", true);
     }
     unset($options['attributes']['restart']);
     if (!file_exists($log_file)) {
         AkFileSystem::file_put_contents($log_file, '');
     }
     System_Daemon::setOption('appName', $app_name);
     System_Daemon::setOption('appDir', AK_BASE_DIR);
     System_Daemon::setOption('logLocation', $log_file);
     System_Daemon::setOption('appRunAsUID', posix_geteuid());
     System_Daemon::setOption('appRunAsGID', posix_getgid());
     System_Daemon::setOption('appPidLocation', $pid_file);
     $this->message("Staring daemon. ({$log_file})");
     System_Daemon::start();
     $dsn = Ak::getStaticVar('dsn');
     defined('AK_SKIP_DB_CONNECTION') && AK_SKIP_DB_CONNECTION ? null : Ak::db($dsn);
     $this->runTask($task_name, $options);
     System_Daemon::stop();
     AkFileSystem::file_delete($pid_file);
     die;
 }
Example #14
0
 public function test_framework_config_locale_update()
 {
     $langs = Ak::langs();
     $translation_key = Ak::randomString(8);
     $this->assertEqual(Ak::t($translation_key), $translation_key);
     $locale_files = AkLocaleManager::updateLocaleFiles();
     list($locales, $core_dictionary) = AkLocaleManager::getCoreDictionary(AK_FRAMEWORK_LANGUAGE);
     $this->assertTrue(isset($core_dictionary[$translation_key]));
     foreach ($langs as $lang) {
         list($locales, $core_dictionary) = AkLocaleManager::getCoreDictionary($lang);
         $this->assertTrue(isset($core_dictionary[$translation_key]));
     }
     foreach ($locale_files as $locale_file) {
         AkFileSystem::file_delete($locale_file);
     }
 }
Example #15
0
 public function testFtpSettings()
 {
     if (!$this->canUseFtpFileHandling()) {
         return false;
     }
     $ftp_path = 'ftp://' . $this->getFtpUser() . ':' . $this->getFtpPassword() . '@' . $this->getFtpHost() . $this->getFtpPath();
     defined('AK_UPLOAD_FILES_USING_FTP') || define('AK_UPLOAD_FILES_USING_FTP', true);
     defined('AK_READ_FILES_USING_FTP') || define('AK_READ_FILES_USING_FTP', false);
     defined('AK_DELETE_FILES_USING_FTP') || define('AK_DELETE_FILES_USING_FTP', true);
     defined('AK_FTP_PATH') || define('AK_FTP_PATH', $ftp_path);
     defined('AK_FTP_AUTO_DISCONNECT') || define('AK_FTP_AUTO_DISCONNECT', true);
     if (AkFileSystem::file_put_contents(AK_CONFIG_DIR . DS . 'test_file.txt', 'hello from ftp')) {
         $text = AkFileSystem::file_get_contents(AK_CONFIG_DIR . DS . 'test_file.txt');
         AkFileSystem::file_delete(AK_CONFIG_DIR . DS . 'test_file.txt');
     }
     $this->ftp_enabled = isset($text) && $text == 'hello from ftp';
     return $this->ftp_enabled;
 }
Example #16
0
 public function tearDown()
 {
     foreach (explode(',', 'aa_ee,bb_cc,dd_ee') as $file) {
         @AkFileSystem::file_delete(AkConfig::getDir('models') . DS . $file . '.php');
     }
 }
Example #17
0
 public function setup()
 {
     $this->installAndIncludeModels(array('Post', 'Comment', 'Tagging', 'Tag'));
     @AkFileSystem::file_delete(AkConfig::getDir('models') . DS . 'post_tag.php');
 }
Example #18
0
 public function test_file_delete()
 {
     if (!RUN_FTP_TESTS) {
         return;
     }
     $this->assertTrue(AkFileSystem::file_delete('cache' . DS . 'test_file_1.txt'));
     $this->assertTrue(AkFileSystem::file_delete('cache' . DS . 'test_file_2.txt'));
     $this->assertTrue(AkFileSystem::file_delete('cache' . DS . 'test_file_3.txt'));
     $this->assertTrue(AkFileSystem::file_delete('cache' . '\\test_file_4.txt'));
     $this->assertTrue(AkFileSystem::file_delete('ak_test_folder/new_folder/test_file.txt'));
 }
Example #19
0
 public function deletePersistedCookie()
 {
     $path = $this->_cookie_path;
     $this->_cookie_path = false;
     if (file_exists(AkConfig::getDir('tmp') . DS . $path)) {
         AkFileSystem::file_delete($path, array('base_path' => AkConfig::getDir('tmp')));
         return;
     }
     return false;
 }
Example #20
0
 protected function _removeOldVersionsFileAndUseMigrationsTable($options)
 {
     $oldfile = $this->_versionPath($options);
     $version = AkFileSystem::file_get_contents($oldfile);
     AkFileSystem::copy($oldfile, $oldfile . '.backup');
     AkFileSystem::file_delete($oldfile);
     $this->log('message', 'got old version from file:' . $oldfile . '=' . $version . ' moved to backup-file:' . $oldfile . '.backup');
     $this->setInstalledVersion($version, $options);
     $this->AkelosMigration->create(array('name' => $this->getInstallerName(), 'version' => $version));
 }
Example #21
0
 public function deleteCreatedFiles()
 {
     foreach ($this->created_files as $file_name) {
         $this->assertTrue(AkFileSystem::file_delete($file_name));
     }
 }
Example #22
0
 public function __destruct()
 {
     if (file_exists($this->_tmp_file)) {
         @AkFileSystem::file_delete($this->_tmp_file);
     }
 }
Example #23
0
 public function setup()
 {
     $this->PluginManager = new AkPluginManager();
     @AkFileSystem::file_delete(AkConfig::getDir('tmp') . DS . 'plugin_repositories.yaml');
 }
 public function test_cleanup()
 {
     @AkFileSystem::file_delete(AkConfig::getDir('models') . DS . 'group_user.php');
 }
Example #25
0
 static function uncompress($compressed_data, $format = 'gzip')
 {
     $key = Ak::randomString(15);
     $compressed_file = AK_TMP_DIR . DS . 's' . $key;
     $uncompressed_file = AK_TMP_DIR . DS . 'd' . $key;
     if (AkFileSystem::file_put_contents($compressed_file, $compressed_data, array('base_path' => AK_TMP_DIR)) !== false) {
         $compressed = gzopen($compressed_file, "r");
         $uncompressed = fopen($uncompressed_file, "w");
         while (!gzeof($compressed)) {
             $string = gzread($compressed, 4096);
             fwrite($uncompressed, $string, strlen($string));
         }
         gzclose($compressed);
         fclose($uncompressed);
     } else {
         trigger_error(Ak::t('Could not write to temporary directory for generating uncompressing file using Ak::uncompress(). Please provide write access to %dirname', array('%dirname' => AK_TMP_DIR)), E_USER_ERROR);
     }
     $result = AkFileSystem::file_get_contents($uncompressed_file, array('base_path' => AK_TMP_DIR));
     AkFileSystem::file_delete($uncompressed_file, array('base_path' => AK_TMP_DIR));
     AkFileSystem::file_delete($compressed_file, array('base_path' => AK_TMP_DIR));
     return $result;
 }