Пример #1
0
 public function setup()
 {
     $this->installAndIncludeModels(array('Post', 'Tag', 'Comment'));
     $Installer = new AkInstaller();
     @$Installer->dropTable('posts_tags');
     @Ak::file_delete(AK_MODELS_DIR . DS . 'post_tag.php');
 }
Пример #2
0
 function Test_file_delete()
 {
     $this->assertFalse(!Ak::file_delete(AK_CACHE_DIR . DS . 'test_file_1.txt'));
     $this->assertFalse(!Ak::file_delete(AK_CACHE_DIR . DS . 'test_file_2.txt'));
     $this->assertFalse(!Ak::file_delete(AK_CACHE_DIR . DS . 'test_file_3.txt'));
     $this->assertFalse(!Ak::file_delete(AK_CACHE_DIR . '/test_file_4.txt'));
     $this->assertFalse(!Ak::file_delete('ak_test_folder/new_folder/test_file.txt'));
 }
Пример #3
0
 public function Test_file_delete()
 {
     $this->assertFalse(!Ak::file_delete(AK_TMP_DIR . DS . 'test_file_1.txt'));
     $this->assertFalse(!Ak::file_delete(AK_TMP_DIR . DS . 'test_file_2.txt'));
     $this->assertFalse(!Ak::file_delete('cache/test_file_3.txt'));
     $this->assertFalse(!Ak::file_delete('cache/test_file_4.txt'));
     $this->assertFalse(!Ak::file_delete('ak_test_folder/new_folder/test_file.txt'));
 }
Пример #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 = Ak::file_get_contents($this->destination_file);
     $this->delete_source_file ? @Ak::file_delete($this->source_file) : null;
     $this->keep_destination_file ? null : Ak::file_delete($this->destination_file);
     return $result;
 }
Пример #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 = Ak::file_get_contents($this->destination_file);
     $this->delete_source_file ? Ak::file_delete($this->source_file) : null;
     $this->keep_destination_file ? null : Ak::file_delete($this->destination_file);
     return $result;
 }
Пример #6
0
 function convert()
 {
     $xdoc2txt_bin = AK_VENDOR_DIR . DS . 'hyperestraier' . DS . 'xdoc2txt.exe';
     if (AK_OS != 'WINDOWS') {
         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 = Ak::file_get_contents($this->destination_file);
     $this->delete_source_file ? @Ak::file_delete($this->source_file) : null;
     $this->keep_destination_file ? null : Ak::file_delete($this->destination_file);
     return $result;
 }
Пример #7
0
 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 ? @Ak::file_delete($this->source_file) : null;
     return $result;
 }
Пример #8
0
 function directory_delete($dir_name, $options = array())
 {
     $default_options = array('ftp' => defined('AK_DELETE_FILES_USING_FTP') && AK_DELETE_FILES_USING_FTP, 'base_path' => AK_BASE_DIR);
     $options = array_merge($default_options, $options);
     $sucess = true;
     $dir_name = Ak::_getRestrictedPath($dir_name, $options);
     if (empty($dir_name)) {
         return false;
     }
     if ($options['ftp']) {
         require_once AK_LIB_DIR . DS . 'AkFtp.php';
         return AkFtp::delete($dir_name);
     } else {
         $items = glob($options['base_path'] . DS . $dir_name . "/*");
         $hidden_items = glob($options['base_path'] . DS . $dir_name . "/.*");
         $fs_items = $items || $hidden_items ? array_merge((array) $items, (array) $hidden_items) : false;
         if ($fs_items) {
             $items_to_delete = array('directories' => array(), 'files' => array());
             foreach ($fs_items as $fs_item) {
                 if ($fs_item[strlen($fs_item) - 1] != '.') {
                     $items_to_delete[is_dir($fs_item) ? 'directories' : 'files'][] = $fs_item;
                 }
             }
             foreach ($items_to_delete['files'] as $file) {
                 Ak::file_delete($file, $options);
             }
             foreach ($items_to_delete['directories'] as $directory) {
                 $sucess = $sucess ? Ak::directory_delete($directory, $options) : $sucess;
             }
         }
         return $sucess ? @rmdir($options['base_path'] . DS . $dir_name) : $sucess;
     }
 }
Пример #9
0
 function _embedReferencedImages($html)
 {
     $images = TextHelper::get_image_urls_from_html($html);
     $html_images = array();
     if (!empty($images)) {
         require_once AK_LIB_DIR . DS . 'AkImage.php';
         require_once AK_LIB_DIR . DS . 'AkActionView' . DS . 'helpers' . DS . 'asset_tag_helper.php';
         foreach ($images as $image) {
             $image = AssetTagHelper::_compute_public_path($image);
             $extenssion = substr($image, strrpos('.' . $image, '.'));
             $image_name = Ak::uuid();
             Ak::file_put_contents(AK_CACHE_DIR . DS . 'tmp' . DS . $image_name . $extenssion, file_get_contents($image));
             $NewImage =& new AkImage(AK_CACHE_DIR . DS . 'tmp' . DS . $image_name . $extenssion);
             $NewImage->save(AK_CACHE_DIR . DS . 'tmp' . DS . $image_name . '.png');
             $html_images[$image] = $image_name . '.png';
             Ak::file_delete(AK_CACHE_DIR . DS . 'tmp' . DS . $image_name);
         }
         $html = str_replace(array_keys($html_images), array_values($html_images), $html);
     }
     return array($html_images, $html);
 }
Пример #10
0
 public function test_should_remove_associated_using_the_right_key()
 {
     $Installer = new AkInstaller();
     @$Installer->dropTable('groups_users');
     @Ak::file_delete(AK_MODELS_DIR . DS . 'group_user.php');
     $this->installAndIncludeModels('User', 'Group', array('instantiate' => true));
     $Admin =& $this->Group->create(array('name' => 'Admin'));
     $Moderator =& $this->Group->create(array('name' => 'Moderator'));
     $this->assertFalse($Admin->hasErrors());
     $this->assertFalse($Moderator->hasErrors());
     $Salavert =& $this->User->create(array('name' => 'Jose'));
     $this->assertFalse($Salavert->hasErrors());
     $Salavert->group->setByIds($Admin->getId(), $Moderator->getId());
     $Salavert =& $this->User->find($Salavert->getId());
     $this->assertEqual(2, $Salavert->group->count());
     $Jyrki =& $this->User->create(array('name' => 'Jyrki'));
     $this->assertFalse($Jyrki->hasErrors());
     $Jyrki->group->setByIds($Admin->getId(), $Moderator->getId());
     $Jyrki =& $this->User->find($Jyrki->getId());
     $this->assertEqual(2, $Jyrki->group->count());
     $Jyrki->destroy();
     $Salavert =& $this->User->find($Salavert->getId());
     $this->assertEqual(2, $Salavert->group->count());
 }
Пример #11
0
 function __destruct()
 {
     if (file_exists($this->_tmp_file)) {
         @Ak::file_delete($this->_tmp_file);
     }
 }
Пример #12
0
 function directory_delete($dir_name, $options = array())
 {
     $default_options = array('ftp' => defined('AK_DELETE_FILES_USING_FTP') && AK_DELETE_FILES_USING_FTP, 'base_path' => AK_BASE_DIR);
     $options = array_merge($default_options, $options);
     $sucess = true;
     $dir_name = str_replace('..', '', rtrim($dir_name, '\\/. '));
     if ($dir_name == '') {
         return false;
     }
     $dir_name = trim(str_replace($options['base_path'], '', $dir_name), DS);
     if ($options['ftp']) {
         require_once AK_LIB_DIR . DS . 'AkFtp.php';
         $dir_name = trim(str_replace(array(DS, '//'), array('/', '/'), $dir_name), '/');
         return AkFtp::delete($dir_name);
     } else {
         if ($fs_items = glob($options['base_path'] . DS . $dir_name . "/*")) {
             $items_to_delete = array('directories' => array(), 'files' => array());
             foreach ($fs_items as $fs_item) {
                 $items_to_delete[is_dir($fs_item) ? 'directories' : 'files'][] = $fs_item;
             }
             foreach ($items_to_delete['files'] as $file) {
                 Ak::file_delete($file, $options);
             }
             foreach ($items_to_delete['directories'] as $directory) {
                 $sucess = $sucess ? Ak::directory_delete($directory, $options) : $sucess;
             }
             return $sucess;
         }
         return rmdir($options['base_path'] . DS . $dir_name);
     }
 }
Пример #13
0
 function test_clear()
 {
     Ak::file_delete(AK_MODELS_DIR.DS.'todo_service.php');
 }
Пример #14
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'])){
                Ak::file_put_contents($pid_file, '');
                Ak::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`;
                    Ak::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)){
            Ak::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();
        Ak::file_delete($pid_file);
        die();
    }
Пример #15
0
 function _moveOldVersionsFileToNewLocation($options)
 {
     $old_filename = $this->_versionPath_Deprecated($options); 
     if (is_file($old_filename)){
         $this->setInstalledVersion(Ak::file_get_contents($old_filename),$options);  
         Ak::file_delete($old_filename); 
         Ak::file_put_contents(AK_APP_INSTALLERS_DIR.DS.'versions'.DS.'NOTE',"Version information is now stored in the temp folder. \n\rYou can safely move this files here over there to tmp/installer_versions/* or delete this directory if empty.");     
     }
 }
Пример #16
0
    function testFtpSettings()
    {
        if(!$this->canUseFtpFileHandling()){
            return false;
        }

        $ftp_path = 'ftp://'.$this->getFtpUser().':'.$this->getFtpPassword().'@'.
        $this->getFtpHost().$this->getFtpPath();

        @define('AK_UPLOAD_FILES_USING_FTP', true);
        @define('AK_READ_FILES_USING_FTP', false);
        @define('AK_DELETE_FILES_USING_FTP', true);
        @define('AK_FTP_PATH', $ftp_path);
        @define('AK_FTP_AUTO_DISCONNECT', true);

        if(@Ak::file_put_contents(AK_CONFIG_DIR.DS.'test_file.txt','hello from ftp')){
            $text = @Ak::file_get_contents(AK_CONFIG_DIR.DS.'test_file.txt');
            @Ak::file_delete(AK_CONFIG_DIR.DS.'test_file.txt');
        }

        $this->ftp_enabled = (isset($text) && $text == 'hello from ftp');

        return $this->ftp_enabled;
    }
Пример #17
0
 function deleteCreatedFiles()
 {
     foreach ($this->created_files as $file_name) {
         $this->assertTrue(Ak::file_delete($file_name));
     }
 }
Пример #18
0
 function setup()
 {
     $this->PluginManager =& new AkPluginManager();
     @Ak::file_delete(AK_TMP_DIR . DS . 'plugin_repositories.yaml');
 }
Пример #19
0
 function Test_file_delete()
 {
     $this->assertTrue(Ak::file_delete(AK_TMP_DIR . DS . 'test_file_1.txt'));
     $this->assertTrue(Ak::file_delete(AK_TMP_DIR . DS . 'test_file_2.txt'));
     $this->assertTrue(Ak::file_delete(AK_TMP_DIR . DS . 'test_file_3.txt'));
     $this->assertTrue(Ak::file_delete(AK_TMP_DIR . '\\test_file_4.txt'));
     $this->assertTrue(Ak::file_delete('ak_test_folder/new_folder/test_file.txt'));
 }
Пример #20
0
 function uninstall()
 {
     $this->dropTable('properties', array('sequence' => true));
     $this->dropTable('properties_property_types', array('sequence' => true));
     @Ak::file_delete(AK_MODELS_DIR . DS . 'property_property_type.php');
 }
Пример #21
0
    public 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(Ak::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 = Ak::file_get_contents($uncompressed_file, array('base_path'=>AK_TMP_DIR));
        Ak::file_delete($uncompressed_file, array('base_path'=>AK_TMP_DIR));
        Ak::file_delete($compressed_file, array('base_path'=>AK_TMP_DIR));
        return $result;
    }
Пример #22
0
 function _deleteTestingModels()
 {
     foreach ($this->_testing_models_to_delete as $file){
         Ak::file_delete($file);
     }
 }
Пример #23
0
 public function deletePersistedCookie()
 {
     if(file_exists($this->_cookie_path)){
         Ak::file_delete($this->_cookie_path);
         $this->_cookie_path = false;
         return;
     }
     return false;
 }
Пример #24
0
 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;
     Ak::file_put_contents($tmp_file, join("\n", $externals));
     `svn propset $extras -q svn:externals -F "$tmp_file" "$plugins_dir"`;
     Ak::file_delete($tmp_file);
 }