Compare commits
3 Commits
f4646f1e3a
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 49240893b5 | |||
| 61728434d3 | |||
| 5736d09dbe |
@@ -201,15 +201,16 @@ class ReceiveProductSync
|
|||||||
throw new \Exception('产品创建失败');
|
throw new \Exception('产品创建失败');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strtotime($product['updated_at']) < strtotime($data['created_at'])) {
|
// 注释更新同步,防止tco同步修改官网手动调整数据
|
||||||
$product->spu = $data['spu'];
|
// else if (strtotime($product['updated_at']) < strtotime($data['created_at'])) {
|
||||||
$product->name = $data['name'];
|
// $product->spu = $data['spu'];
|
||||||
$product->category_id = $product_category['id'];
|
// $product->name = $data['name'];
|
||||||
$product->status = Operate_Of_ReceiveSync::Disable == $data['operate'] ? -1 : 1;
|
// $product->category_id = $product_category['id'];
|
||||||
if (!$product->save()) {
|
// $product->status = Operate_Of_ReceiveSync::Disable == $data['operate'] ? -1 : 1;
|
||||||
throw new \Exception('产品更新失败');
|
// if (!$product->save()) {
|
||||||
}
|
// throw new \Exception('产品更新失败');
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
return error(sprintf('%s %s:%d', $th->getMessage(), $th->getFile(), $th->getLine()));
|
return error(sprintf('%s %s:%d', $th->getMessage(), $th->getFile(), $th->getLine()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -244,6 +244,25 @@ class ImageMigrator:
|
|||||||
if self.verbose:
|
if self.verbose:
|
||||||
print("连接已关闭")
|
print("连接已关闭")
|
||||||
|
|
||||||
|
def chown_target(self, owner: str, target_path: str) -> bool:
|
||||||
|
command = f"sudo chown {owner} {target_path}"
|
||||||
|
stdin, stdout, stderr = self.target_client.exec_command(command)
|
||||||
|
# 如果需要输入sudo密码
|
||||||
|
if "sudo" in command and self.target_config.password:
|
||||||
|
stdin.write(self.target_config.password + "\n")
|
||||||
|
stdin.flush()
|
||||||
|
|
||||||
|
if self.verbose:
|
||||||
|
# 获取输出和错误
|
||||||
|
# output = stdout.read().decode()
|
||||||
|
error = stderr.read().decode()
|
||||||
|
exit_code = stdout.channel.recv_exit_status()
|
||||||
|
if exit_code == 0:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print(f"DEBUG chown_target: 修改 {target_path} 的所有者失败: {error}")
|
||||||
|
return False
|
||||||
|
|
||||||
def ensure_target_directory(self, remote_dir: str) -> bool:
|
def ensure_target_directory(self, remote_dir: str) -> bool:
|
||||||
"""确保目标目录存在(递归创建)"""
|
"""确保目标目录存在(递归创建)"""
|
||||||
try:
|
try:
|
||||||
@@ -298,11 +317,17 @@ class ImageMigrator:
|
|||||||
f"DEBUG ensure_target_directory: 创建目录: {current_path}"
|
f"DEBUG ensure_target_directory: 创建目录: {current_path}"
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
|
# 创建目录
|
||||||
self.target_sftp.mkdir(current_path)
|
self.target_sftp.mkdir(current_path)
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print(
|
print(
|
||||||
f"DEBUG ensure_target_directory: 目录创建成功: {current_path}"
|
f"DEBUG ensure_target_directory: 目录创建成功: {current_path}"
|
||||||
)
|
)
|
||||||
|
# 修改目录所有者
|
||||||
|
if self.chown_target("www", current_path) and self.verbose:
|
||||||
|
print(
|
||||||
|
f"DEBUG ensure_target_directory: {current_path} 所有者修改为 www 成功"
|
||||||
|
)
|
||||||
except Exception as mkdir_e:
|
except Exception as mkdir_e:
|
||||||
# 如果创建失败,可能是权限问题或目录已存在
|
# 如果创建失败,可能是权限问题或目录已存在
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
@@ -519,6 +544,8 @@ class ImageMigrator:
|
|||||||
print(f"DEBUG: 目录stat也失败: {stat_e}")
|
print(f"DEBUG: 目录stat也失败: {stat_e}")
|
||||||
|
|
||||||
self.target_sftp.put(temp_path, target_path)
|
self.target_sftp.put(temp_path, target_path)
|
||||||
|
if self.chown_target("www", target_path) and self.verbose:
|
||||||
|
print(f"DEBUG transfer_file: {target_path} 所有者修改为 www 成功")
|
||||||
|
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print("DEBUG: 上传完成")
|
print("DEBUG: 上传完成")
|
||||||
|
|||||||
Reference in New Issue
Block a user