This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Akhil
Akhil

I am migrating data from one cms(Modx) to October CMS. I have migrated all the content data using custom coding but the problem is with inserting/relating files data to "System File Table" of October CMS.

          In model i have used public $attachOne = ['image' => ['System\Models\File']];

/////////// For example : My image is at this location 'F:\wamp\www\modx.vh1.in\assets\images\1_1369729966.jpg' I want to copy this file as per OctoberCms to public folder and to relate files to system file table. How can i do this and where to writethis code.

$file = new System\Models\File;

$contents = $file::get( 'F:\wamp\www\modx.vh1.in\assets\images\1_1369729966.jpg');

$file->data = $contents;

$file->save();

$model->image()->add($file);

Last updated

Akhil
Akhil

Migration code

       $models = MusicCurrent::whereNotNull('published')
        ->orderBy('id','asc')
        ->skip(0)
        ->take(1000000)
        ->get();
    $baseUrlForImage = 'F:\wamp\www\modx.vh1.in';

    foreach($models as $model){
        if($model->image && ($model->image != '')){
            $contents = $baseUrlForImage.$model->image;
            if(file_exists($contents)){
                $file = new \System\Models\File;//

                $file->data = $contents;
                $file->save();

                $model->image()->add($file);
            }else{
                echo $model->id;
                die();    
            }
        }
    }

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.